fix(plist): keep literal carriage returns in XML plist keys and strings (#12236)

The XML plist reader replaced every literal CR and CRLF with LF before
parsing. CoreFoundation keeps them, so REA reported a different string than
plutil for the same file, and two keys that differ only in their line ending
collapsed into one repeated key.

The document is now parsed as written. Source spans for integer, real, date
and data literals already count CR, CRLF and LF as one line break each.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Lewis WangandClaude Fable 5.2 authored and GitHub committed 2026-11-19 06:42:48 -05:00
1 parent a143a2811e
commit 89b2d398eb
4 files changed
+21 -3

No files matched your search

+1 -1
View File
@@ -412,7 +412,7 @@ describe("OpenStep plist owned depth", () => {
});
});
it.each(["\u0085", "\u2028", "\u2029"])(
it.each(["\r", "\r\n", "\u0085", "\u2028", "\u2029"])(
"preserves key identity around inter-element separator %j",
(separator) => {
const parsed = parseXmlPropertyList(
+14
View File
@@ -301,6 +301,20 @@ it("binds raw literals to their nodes across normalized line endings and UTF-16
]);
});
it("keeps literal carriage returns in keys and strings, as CoreFoundation does", () => {
// plutil reads these four keys as distinct and each value as written.
const parsed = parseXmlPropertyList(
"<plist>\r<dict>\r<key>a\r\nb</key><string>x\ry\r\nz</string>\r<key>a\nb</key><string><![CDATA[c\rd]]></string>\r<key>a\rb</key>\r<integer>42</integer>\r<key>data</key>\r<data>\rAAEC\r\n</data>\r</dict>\r</plist>\r",
);
expect(parsed.value).toEqual({
"a\r\nb": "x\ry\r\nz",
"a\nb": "c\rd",
"a\rb": 42,
data: new Uint8Array([0, 1, 2]),
});
expect(parsed.duplicateKeys).toMatchObject({ dictionaries: 0 });
});
it("preserves Unicode line separators in plist string values", () => {
const value = "a\u0085b\u2028c\u2029d";
expect(
+3 -2
View File
@@ -27,8 +27,9 @@ export const readXmlPlistSource = (
text: string,
maximumDepth = MAX_PLIST_DEPTH,
) => {
const normalized = text.replace(XML_LINE_ENDING, "\n");
const parsed = parseXmlDocument(normalized, {
// CoreFoundation keeps a literal CR in a key or string, so the document is
// read as written; XML 1.0 line-ending normalization would rewrite both.
const parsed = parseXmlDocument(text, {
doctype: "allow",
lineEndings: "preserve",
});
@@ -229,6 +229,8 @@ describe.skipIf(process.platform !== "darwin")(
"<key>CFBundleIdentifier</key><string>com.example.types</string>",
"<key>Blob</key><data>AAEC</data>",
"<key>Separators</key><string>a\u0085b\u2028c\u2029d</string>",
// CoreFoundation keeps a literal CR, so plutil's binary conversion holds it too.
"<key>Returns</key><string>a\rb\r\nc\nd</string>",
"<key>Built</key><date>2020-01-01T00:00:00Z</date>",
// Parse the unsigned extended year as a UTC field, without JS string-date inference.
"<key>Far</key><date>11507-08-17T05:20:00Z</date>",
@@ -263,6 +265,7 @@ describe.skipIf(process.platform !== "darwin")(
CFBundleIdentifier: "com.example.types",
Blob: { $plist_type: "data", base64: "AAEC" },
Separators: "a\u0085b\u2028c\u2029d",
Returns: "a\rb\r\nc\nd",
Built: {
$plist_type: "date",
iso8601: "2020-01-01T00:00:00.000Z",