From b55230ce3fb64caeae8080965c2fc2e594b14073 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 9 Apr 2026 15:34:37 -0400 Subject: [PATCH] fix normalize_xml_tags() --- src/agent/context.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/agent/context.rs b/src/agent/context.rs index 3d5e969..5064405 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -447,20 +447,18 @@ fn format_tool_call_xml(name: &str, args_json: &str) -> String { fn normalize_xml_tags(text: &str) -> String { let mut result = String::with_capacity(text.len()); let mut chars = text.chars().peekable(); + let mut in_tag = false; + while let Some(ch) = chars.next() { if ch == '<' { - let mut tag = String::from('<'); - for inner in chars.by_ref() { - if inner == '>' { - tag.push('>'); - break; - } else if inner.is_whitespace() { - // Skip whitespace inside tags - } else { - tag.push(inner); - } - } - result.push_str(&tag); + in_tag = true; + result.push(ch); + } else if ch == '>' { + result.push(ch); + in_tag = false; + } else if in_tag && ch.is_whitespace() { + // Skip whitespace inside tags (between < and >) + continue; } else { result.push(ch); }