diff --git a/crates/viport-hle/src/runtime.rs b/crates/viport-hle/src/runtime.rs index ae33173..3b10a5f 100644 --- a/crates/viport-hle/src/runtime.rs +++ b/crates/viport-hle/src/runtime.rs @@ -153,7 +153,7 @@ fn elements(text: &str) -> Vec<(String, String)> { } else if rest.starts_with("").map(|e| e + 3) } else { - rest.find('>').map(|e| e + 1) + tag_end(rest) }; let Some(end) = end else { break }; let tag = &rest[1..end - 1]; @@ -186,6 +186,21 @@ fn elements(text: &str) -> Vec<(String, String)> { out } +/// Where the tag that starts `text` ends, past its `>`; a `>` in a quoted +/// attribute value is part of the value (XML allows it there unescaped). +fn tag_end(text: &str) -> Option { + let mut quote = None; + for (at, c) in text.char_indices() { + match (quote, c) { + (None, '"' | '\'') => quote = Some(c), + (Some(open), _) if c == open => quote = None, + (None, '>') => return Some(at + 1), + _ => {} + } + } + None +} + static TITLE: Mutex> = Mutex::new(None); pub fn set_title(title: Title) { @@ -260,6 +275,15 @@ mod tests { assert_eq!(throttling_opt_outs(true), PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION); } + #[test] + fn a_quoted_angle_bracket_does_not_end_its_tag() { + let text = " B\" Description='x>y'/>\ + 639AA8DD\ + 64"; + let t = Title::from_manifest(text); + assert_eq!((t.id, t.storage_bytes), (0x639A_A8DD, 64 << 20)); + } + #[test] fn reads_title_id_store_id_and_storage_quota() { let text = "\u{feff}\n\