Repository navigation
fix(extract): do not resolve keys to Object.prototype members - #334
Merged
Merged
Conversation
getNestedValue and setNestedValue followed inherited properties, so a key named constructor, toString or valueOf was read as already present (a function) and then dropped by JSON.stringify, and page.constructor.title was written as a flat key next to an empty page object. Look up own properties only, and define __proto__ as a plain key instead of letting a key such as __proto__.x write to Object.prototype.
Member
|
Thanks again, another good catch. I could reproduce it on main. I merged it and added the same own-property check in two more places in translation-manager.ts: the nesting conflict check and the key order for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keys that share a name with an
Object.prototypemember are lost or misplaced byextract.On main,
locales/en/translation.jsonbecomes:{ "page": {}, "page.constructor.title": "Builder title" }getNestedValue({}, 'constructor', '.')returnsObject, so the key is treated as already present, its "value" is the function, andJSON.stringifydrops it. InsetNestedValue,page.constructorresolves to the inherited function, hits the primitive-conflict branch and the key is written flat at the root. A key such as__proto__.xgoes further and assignsxonObject.prototypeof the running process.Fix:
getNestedValue,setNestedValueanddeleteNestedValueonly follow own properties, and__proto__is defined as a plain own key. With the change the output is:{ "constructor": "Builder", "page": { "constructor": { "title": "Builder title" } }, "toString": "Text", "valueOf": "Value" }Tests: 3 unit tests in
nested-objects.test.tsand an extractor test inextractor.builtin-key-names.test.ts; all 4 fail on main.vitest run1646 passed,eslint .andtsc --noEmitclean.