Merge pull request #894 from morluto/fix/plist-prototype-key-reporting

fix(plist): report omitted __proto__ entries in signatures and Interface Builder
This commit is contained in:
Kaoru0822
2026-10-07 02:12:34 -07:00
committed by GitHub
6 changed files with 157 additions and 23 deletions
+20
View File
@@ -39,6 +39,26 @@ it("keeps __proto__ text in strings, comments, and similar keys", () => {
});
});
it("keeps an entity-encoded key that decodes to the placeholder", () => {
const text = plist(
"<dict><key>&#95;&#95;rea_prototype_key__</key><string>kept</string><key>__proto__</key><string>x</string></dict>",
);
expect(parseXmlPropertyList(text)).toEqual({
value: { __rea_prototype_key__: "kept" },
omittedPrototypeKeys: 1,
});
});
it("keeps entity-like text beyond Unicode in comments and CDATA", () => {
const text = plist(
"<!-- &#99999999999; --><dict><key>raw</key><string><![CDATA[&#x110000;]]></string><key>__proto__</key><string>x</string></dict>",
);
expect(parseXmlPropertyList(text)).toEqual({
value: { raw: "&#x110000;" },
omittedPrototypeKeys: 1,
});
});
it("omits own __proto__ entries that JSON decoding creates", () => {
const decoded: unknown = JSON.parse(
'{"__proto__":{"x":1},"a":[{"__proto__":2,"b":3}]}',
+18 -4
View File
@@ -56,13 +56,23 @@ const XML_ENTITIES: Readonly<Record<string, string>> = {
quot: '"',
};
/**
* Expand XML character and predefined entity references. A reference beyond
* Unicode stays as written: comments and CDATA may hold such text literally,
* and the XML decoder rejects it anywhere else.
*/
const decodeXmlText = (text: string): string =>
text.replace(
/&(?:#x([\da-f]+)|#(\d+)|([a-z]+));/giu,
(entity, hex?: string, decimal?: string, name?: string) => {
if (hex !== undefined) return String.fromCodePoint(parseInt(hex, 16));
if (decimal !== undefined)
return String.fromCodePoint(parseInt(decimal, 10));
const codePoint =
hex !== undefined
? parseInt(hex, 16)
: decimal !== undefined
? parseInt(decimal, 10)
: undefined;
if (codePoint !== undefined)
return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : entity;
return (name === undefined ? undefined : XML_ENTITIES[name]) ?? entity;
},
);
@@ -75,8 +85,12 @@ const decodeXmlText = (text: string): string =>
export const parseXmlPropertyList = (
text: string,
): PropertyListWithoutPrototypeKeys => {
// The decoded text holds every key the decoder can produce, including
// entity-encoded spellings of the placeholder, so no source key aliases it.
// Decoding comment or CDATA text too can only lengthen the placeholder.
const decoded = decodeXmlText(text);
let placeholder = "__rea_prototype_key__";
while (text.includes(placeholder)) placeholder = `_${placeholder}`;
while (decoded.includes(placeholder)) placeholder = `_${placeholder}`;
const substituted = text.replace(
KEY_TOKEN,
(token, plain?: string, cdata?: string) =>