diff --git a/crates/svg/src/guard.rs b/crates/svg/src/guard.rs index 58390f261..e2a11ae6a 100644 --- a/crates/svg/src/guard.rs +++ b/crates/svg/src/guard.rs @@ -49,10 +49,20 @@ fn past(b: &[u8], from: usize, close: &[u8]) -> usize { b.get(from..).and_then(|rest| rest.windows(close.len()).position(|w| w == close)).map_or(b.len(), |n| from + n + close.len()) } +/// Whether `rest` starts an element, attribute list or notation declaration. XML readers skip +/// these to their first `>`, quotes and brackets included. +fn skipped_to_first_close(rest: &[u8]) -> bool { + [b"`, or past the `[` that opens a document type's internal subset. -/// Quoted literals are skipped, so a `"), _ if rest.starts_with(b" past(b, i + 2, b"?>"), _ => i + 1, @@ -552,6 +563,7 @@ mod tests { format!("{large}]>"), format!(""), format!("{large}]>"), + format!("{large}]>"), ] { assert!(expansion_too_large(&format!("{hidden}"))); } @@ -564,7 +576,7 @@ mod tests { fn markers_in_a_literal_hide_no_markup_from_the_depth_or_attribute_counts() { let tenth = DEPTH / 10 + 1; let nested = format!("{}{}", "".repeat(tenth), "".repeat(tenth)); - for bait in ["", "", "\">"] { + for bait in ["", "", "\">", ""] { assert!(too_deep(&format!("]>&a;")), "{bait}"); } // Comments and instructions in a value open and close no element. @@ -577,6 +589,8 @@ mod tests { assert!(!too_deep(&format!("{}", svg(&groups(8))))); let many = (0..5000).map(|i| format!(" a{i}=\"1\"")).collect::(); assert!(wide(&format!("\">'>]>&e;"))); + // An element declaration ends at its first `>`, so a `]` inside it does not end the subset. + assert!(wide(&format!("'>]>&e;"))); } #[test]