Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion crates/viport-hle/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn elements(text: &str) -> Vec<(String, String)> {
} else if rest.starts_with("<![CDATA[") {
rest.find("]]>").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];
Expand Down Expand Up @@ -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<usize> {
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<Option<Title>> = Mutex::new(None);

pub fn set_title(title: Title) {
Expand Down Expand Up @@ -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 = "<Game><ShellVisuals DefaultDisplayName=\"A > B\" Description='x>y'/>\
<TitleId>639AA8DD</TitleId>\
<PersistentLocalStorage><SizeMB>64</SizeMB></PersistentLocalStorage></Game>";
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}<?xml version=\"1.0\"?>\n<Game configVersion=\"1\">\
Expand Down