fix normalize_xml_tags()

This commit is contained in:
Kent Overstreet 2026-04-09 15:34:37 -04:00
parent 8d14c59d56
commit b55230ce3f

View file

@ -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);
}