fix(xfa): reject repeated leading BOM before parsing spans (#2176)

This commit is contained in:
FredApps authored and GitHub committed 2026-11-18 14:36:07 +07:00
1 parent 80f1cedd4b
commit c03ba68ab3
1 file changed
+13
+13
View File
@@ -194,6 +194,10 @@ impl Document {
// quick-xml excludes a leading UTF-8 BOM from its buffer positions.
// Parse it explicitly so every stored range still addresses the original input.
let input = text.strip_prefix('\u{feff}').unwrap_or(text);
// A second U+FEFF is content outside the root, not another encoding marker.
if input.starts_with('\u{feff}') {
return Err("multiple leading XML byte-order marks".to_string());
}
let source_offset = text.len() - input.len();
let mut events = opts.events(input.as_bytes());
let mut nodes: Vec<NodeData> = Vec::new();
@@ -435,6 +439,15 @@ mod tests {
}
}
#[test]
fn repeated_leading_bom_is_rejected_before_event_parsing() {
for prefix in ["\u{feff}\u{feff}", "\u{feff}\u{feff}\u{feff}"] {
for body in ["<r><é/></r>", "<?xml version='1.0'?><r><é>text</é></r>"] {
assert!(Document::parse(&format!("{prefix}{body}")).is_err());
}
}
}
#[test]
fn inherited_namespace_copies_obey_aggregate_byte_admission() {
let uri = format!("urn:{}", "x".repeat(124));