Skip to content

fix: keep "__proto__" dictionary keys as own properties - #58

Merged
joeferner merged 1 commit into
joeferner:masterfrom
bardrop-oss:fix-proto-dictionary-key
Nov 14, 2026
Merged

joeferner merged 1 commit into
joeferner:masterfrom
bardrop-oss:fix-proto-dictionary-key

Conversation

@bardrop

@bardrop bardrop commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #57

parseDictionary filled the result with dict[key] = val. For the key __proto__ that runs the Object.prototype.__proto__ setter, so:

  • the __proto__ entry was missing from the parsed object, and
  • if its value was a dictionary, it became the object's prototype (r.isAdmin === true in the issue's repro).

Now every entry is added with Object.defineProperty (enumerable, writable, configurable, same as a normal assignment), so __proto__ shows up as an own property like it does in Python's plistlib. I did it for every key, not just key === "__proto__", because the parser doesn't require keys to be strings, and a non-string key such as an array ["__proto__"] would still coerce to "__proto__" and hit the setter.

Testing: new test in test/parse.test.ts uses the binary plist from the issue (made with plistlib.dumps(..., fmt=plistlib.FMT_BINARY)). It fails on master and passes here. npm test (12 pass), npm run typecheck and npm run smoke pass. npm run lint shows the same 12 problems as on master, none in the changed lines.

parseDictionary assigned entries with dict[key] = val. For the key
"__proto__" (or any key object that coerces to it) that calls the
Object.prototype setter, so the entry was dropped and a dictionary value
became the prototype of the result. Define every entry with
Object.defineProperty instead.

Fixes #57
@bardrop
bardrop force-pushed the fix-proto-dictionary-key branch from 0c31316 to ea94b6b Compare November 14, 2026 08:29
@joeferner
joeferner merged commit d505731 into joeferner:master Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dictionary key "__proto__" sets the prototype of the parsed object instead of becoming a key

2 participants