Fixed case part of bug #64874 ("json_decode handles whitespace and case-sensitivity incorrectly")#527
Closed
hikari-no-yume wants to merge 1 commit intophp:PHP-5.6from
Closed
Fixed case part of bug #64874 ("json_decode handles whitespace and case-sensitivity incorrectly")#527hikari-no-yume wants to merge 1 commit intophp:PHP-5.6from
hikari-no-yume wants to merge 1 commit intophp:PHP-5.6from
Conversation
…se-sensitivity incorrectly")
Contributor
|
I've merged the PR to 5.6 and master. |
Contributor
Author
|
Thank you very much for merging it! |
|
This becomes a vector for detecting whether PHP >= 5.6 is running on a server if the custom application code exposes an API that accepts JSON input. I think this fact should be in the PHP 5.6 migration documentation, as it may be of concern to some sys admins. Forgive me in advance, I was not sure where the best place is to raise this concern. |
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.
This request fixes the JSON parser's handling of top-level true/false/null. By that I mean a lone true/false/null value, not one inside an array of object. Hence,
json_decode("True");(currently valid) is affected butjson_decode("[True]");(currently invalid) is not.At present, there is a bug where non-lowercase forms (e.g.
TrueortRUE) of these top-level values are accepted by the parser without erroring. This behaviour is not compliant with the JSON.org standard, nor the IETF RFC, nor the ECMA standard. It is also inconsistent with other JSON implementations. Were I to tryJSON.parse('True');in JavaScript orjson.loads('true')in Python, I would be met with an error. The function is even inconsistent with itself in this respect, as[True]will fail butTruewill not. I suspect that this behaviour was not intended and simply came about because of someone failing to read the specification and assuming case-insensitivity.Hence I propose this patch. It replaces
strcasecmpwithstrcmpwhere the former was used incorrectly. It is a minor backwards-compatibility break, so I am targeting this at 5.6. However I believe that it is very unlikely that any code relied on this bug, since all JSON serialisers output lowercase literals, and any hand-written JSON is likely not a lone true, false or null value.In the event that code relied on this bug, they could simply do something like this:
So, I ask that this is merged, as a tiny backwards-compatibility break but bringing PHP into harmony with other JSON implementations and the specification.
EDIT: I should note that this is a literal 3-line change, replacing
strcasecmpforstrcmpon three different lines.EDIT 2: dsp asked me where in the JSON standard it says that it must be lowercase. It's in RFC 4627, page 2: