Repository navigation
Fix JSON.parse source records for duplicate keys - #1851
Open
jeromeleong wants to merge 1 commit into
Open
jeromeleong wants to merge 1 commit into
jeromeleong wants to merge 1 commit into
Conversation
JSON.parse keeps a parse record for each object member, including duplicate keys, so the reviver can access its source text. With up to eight input members, json_parse_record_find() used a forward linear search and returned the first matching record. The hash-table path used for larger inputs returns the last matching record instead.
For {"x":1.0,"x":1}, this exposed source "1.0" alongside the value 1, but adding unrelated members past the threshold changed the source to "1". Since both literals parse to the same value, the SameValue check accepted the stale record. For unequal duplicate values, that check rejected the record and incorrectly omitted source.
Search the linear entries backwards so both paths select the last occurrence, as required by CreateJSONParseRecord. This keeps context.source associated with the surviving property value regardless of the input member count.
This branch has not been deployed
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.
JSON.parse keeps a parse record for each object member, including duplicate keys, so the reviver can access its source text. With up to eight input members, json_parse_record_find() used a forward linear search and returned the first matching record. The hash-table path used for larger inputs returns the last matching record instead.
For {"x":1.0,"x":1}, this exposed source "1.0" alongside the value 1, but adding unrelated members past the threshold changed the source to "1". Since both literals parse to the same value, the SameValue check accepted the stale record. For unequal duplicate values, that check rejected the record and incorrectly omitted source.
Search the linear entries backwards so both paths select the last occurrence, as required by CreateJSONParseRecord. This keeps context.source associated with the surviving property value regardless of the input member count.