fix(artifacts): respect XML plist byte-order marks (#514)

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-05 14:59:21 +08:00
committed by GitHub
parent 80777d96da
commit 23c4eba5b3
5 changed files with 190 additions and 1 deletions
@@ -0,0 +1,17 @@
# Foundation XML archive encoding fixture
`producer.swift` creates an actual NSKeyedArchiver XML representation, then
uses Foundation string encoding to produce BOM-marked UTF-16 little- and
big-endian representations of the same XML graph. Foundation's
PropertyListSerialization reads both representations successfully; `plutil
-lint` also accepts all three files.
```sh
xcrun swiftc producer.swift -o writer
./writer archive.xml little-endian.plist big-endian.plist
plutil -lint archive.xml little-endian.plist big-endian.plist
```
Only the UTF-8 XML source capture is committed. The tests encode its same text
as UTF-16 so no compiled binaries or binary fixtures are committed. This is
format/filesystem verification; no archived classes are instantiated by REA.
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>$archiver</key>
<string>NSKeyedArchiver</string>
<key>$objects</key>
<array>
<string>$null</string>
<dict>
<key>$class</key>
<dict>
<key>CF$UID</key>
<integer>4</integer>
</dict>
<key>NS.keys</key>
<array>
<dict>
<key>CF$UID</key>
<integer>2</integer>
</dict>
</array>
<key>NS.objects</key>
<array>
<dict>
<key>CF$UID</key>
<integer>3</integer>
</dict>
</array>
</dict>
<string>text</string>
<string>Café</string>
<dict>
<key>$classes</key>
<array>
<string>NSDictionary</string>
<string>NSObject</string>
</array>
<key>$classname</key>
<string>NSDictionary</string>
</dict>
</array>
<key>$top</key>
<dict>
<key>root</key>
<dict>
<key>CF$UID</key>
<integer>1</integer>
</dict>
</dict>
<key>$version</key>
<integer>100000</integer>
</dict>
</plist>
@@ -0,0 +1,13 @@
import Foundation
let archiver = NSKeyedArchiver(requiringSecureCoding: false)
archiver.outputFormat = .xml
archiver.encode(["text": "Café"] as NSDictionary, forKey: NSKeyedArchiveRootObjectKey)
archiver.finishEncoding()
let xml = String(data: archiver.encodedData, encoding: .utf8)!
let utf16 = xml.replacingOccurrences(of: "UTF-8", with: "UTF-16").data(using: .utf16)!
let _: Any = try PropertyListSerialization.propertyList(from: utf16, options: [], format: nil)
try archiver.encodedData.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))
try utf16.write(to: URL(fileURLWithPath: CommandLine.arguments[2]))
let bigEndian = Data([0xfe, 0xff]) + xml.replacingOccurrences(of: "UTF-8", with: "UTF-16").data(using: .utf16BigEndian)!
let _: Any = try PropertyListSerialization.propertyList(from: bigEndian, options: [], format: nil)
try bigEndian.write(to: URL(fileURLWithPath: CommandLine.arguments[3]))