|
@@ -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
|
|
|
|
|
+/// `<TitleId><!-- generated -->639AA8DD</TitleId>`, 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("<!--") {
|
|
|
|
|
+ let Some(end) = rest[open..].find("-->") 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`)
|
|
/// 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
|
|
/// and its trimmed text up to the first child, the predefined entities
|
|
|
/// decoded; comments, CDATA sections, declarations and attributes are
|
|
/// decoded; comments, CDATA sections, declarations and attributes are
|
|
@@ -161,10 +187,10 @@ fn elements(text: &str) -> Vec<(String, String)> {
|
|
|
.next()
|
|
.next()
|
|
|
.unwrap_or("");
|
|
.unwrap_or("");
|
|
|
path.push(name);
|
|
path.push(name);
|
|
|
- let body = rest[..rest.find('<').unwrap_or(rest.len())].trim();
|
|
|
|
|
|
|
+ let body = field_text(rest);
|
|
|
let body = [("<", "<"), (">", ">"), (""", "\""), ("'", "'"), ("&", "&")]
|
|
let body = [("<", "<"), (">", ">"), (""", "\""), ("'", "'"), ("&", "&")]
|
|
|
.iter()
|
|
.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));
|
|
out.push((path.join("/"), body));
|
|
|
if closed {
|
|
if closed {
|
|
|
path.pop();
|
|
path.pop();
|
|
@@ -260,4 +286,17 @@ mod tests {
|
|
|
assert_eq!(t.store_id, "9&C");
|
|
assert_eq!(t.store_id, "9&C");
|
|
|
assert_eq!(Title::from_manifest("").storage_bytes, 0);
|
|
assert_eq!(Title::from_manifest("").storage_bytes, 0);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn inline_comments_do_not_truncate_a_field() {
|
|
|
|
|
+ let text = "<Game>\
|
|
|
|
|
+ <TitleId><!-- generated -->639AA8DD</TitleId>\
|
|
|
|
|
+ <StoreId>9&<!-- keep -->C</StoreId>\
|
|
|
|
|
+ <PersistentLocalStorage><SizeMB><!-- n -->1024</SizeMB></PersistentLocalStorage>\
|
|
|
|
|
+ </Game>";
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|