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 { fn normalize_xml_tags(text: &str) -> String {
let mut result = String::with_capacity(text.len()); let mut result = String::with_capacity(text.len());
let mut chars = text.chars().peekable(); let mut chars = text.chars().peekable();
let mut in_tag = false;
while let Some(ch) = chars.next() { while let Some(ch) = chars.next() {
if ch == '<' { if ch == '<' {
let mut tag = String::from('<'); in_tag = true;
for inner in chars.by_ref() { result.push(ch);
if inner == '>' { } else if ch == '>' {
tag.push('>'); result.push(ch);
break; in_tag = false;
} else if inner.is_whitespace() { } else if in_tag && ch.is_whitespace() {
// Skip whitespace inside tags // Skip whitespace inside tags (between < and >)
} else { continue;
tag.push(inner);
}
}
result.push_str(&tag);
} else { } else {
result.push(ch); result.push(ch);
} }