fix(plist): reject XML dictionary keys without values

Fixes #6682
This commit is contained in:
morluto
2026-10-23 20:59:11 +08:00
parent 78ce91f1c2
commit 869d2bc2ec
2 changed files with 13 additions and 1 deletions
+11
View File
@@ -38,6 +38,17 @@ it("keeps document-level processing instructions outside plist members", () => {
expect(parsed.numberLiterals.incomplete).toBe(false);
});
it("rejects a dictionary key without a value and preserves an explicit empty string", () => {
expect(() =>
parseXmlPropertyList("<plist><dict><key>missing</key></dict></plist>"),
).toThrow("Missing value for key while parsing <dict/>");
expect(
parseXmlPropertyList(
"<plist><dict><key>empty</key><string/></dict></plist>",
).value,
).toEqual({ empty: "" });
});
it.each([
["CDATA", "<![CDATA[before<?rea content?>after]]>"],
["escaped text", "before&lt;?rea content?&gt;after"],
+2 -1
View File
@@ -85,7 +85,8 @@ export const decodeXmlPropertyList = (text: string) => {
key = undefined;
}
}
if (key !== undefined) entries.push([key, ""]);
if (key !== undefined)
throw new TypeError("Missing value for key while parsing <dict/>");
// Define own properties safely, including __proto__; the caller owns omission accounting.
return Object.fromEntries(entries);
}