diff --git a/crates/victory-hle/src/runtime.rs b/crates/victory-hle/src/runtime.rs
index e90aa58..f26b96f 100644
--- a/crates/victory-hle/src/runtime.rs
+++ b/crates/victory-hle/src/runtime.rs
@@ -125,6 +125,32 @@ impl Title {
}
}
+/// The trimmed text of one element: comments inside it are skipped, not
+/// treated as the end of its value. A manifest generator can write
+/// `639AA8DD`, which must still give
+/// the title's id rather than an empty field.
+fn field_text(rest: &str) -> String {
+ let mut out = String::new();
+ let mut rest = rest;
+ loop {
+ let Some(open) = rest.find('<') else {
+ out.push_str(rest);
+ break;
+ };
+ out.push_str(&rest[..open]);
+ if rest[open..].starts_with("") else {
+ break;
+ };
+ rest = &rest[open + end + 3..];
+ } else {
+ // A child element, a closing tag or anything else ends the text.
+ break;
+ }
+ }
+ out.trim().to_owned()
+}
+
/// Each element of an XML text as its path from the root (`Game/TitleId`)
/// and its trimmed text up to the first child, the predefined entities
/// decoded; comments, CDATA sections, declarations and attributes are
@@ -161,10 +187,10 @@ fn elements(text: &str) -> Vec<(String, String)> {
.next()
.unwrap_or("");
path.push(name);
- let body = rest[..rest.find('<').unwrap_or(rest.len())].trim();
+ let body = field_text(rest);
let body = [("<", "<"), (">", ">"), (""", "\""), ("'", "'"), ("&", "&")]
.iter()
- .fold(body.to_owned(), |b, (entity, c)| b.replace(entity, c));
+ .fold(body, |b, (entity, c)| b.replace(entity, c));
out.push((path.join("/"), body));
if closed {
path.pop();
@@ -260,4 +286,17 @@ mod tests {
assert_eq!(t.store_id, "9&C");
assert_eq!(Title::from_manifest("").storage_bytes, 0);
}
+
+ #[test]
+ fn inline_comments_do_not_truncate_a_field() {
+ let text = "\
+ 639AA8DD\
+ 9&C\
+ 1024\
+ ";
+ let t = Title::from_manifest(text);
+ assert_eq!(t.id, 0x639A_A8DD);
+ assert_eq!(t.store_id, "9&C");
+ assert_eq!(t.storage_bytes, 1024 << 20);
+ }
}