Preserve non-canonical numeric nested JSON keys#1893
Open
upuddu wants to merge 1 commit into
Open
Conversation
The nested JSON tokenizer used Python's int() to decide whether a token is a number. int() is lenient and accepts non-canonical forms such as 007, 1_000, +5 or whitespace-padded values, so numeric-looking object keys were silently normalized (e.g. 007 became 7). Only treat a token as a number when it is written in its canonical form, keeping everything else as verbatim text. Canonical integers, including negative indexes, are unaffected.
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.
HTTPie's nested-JSON syntax decides whether a key segment is an array index or a text key by calling
int()on it.int()is lenient - it also accepts007,1_000,+5, and whitespace-padded values - so numeric-looking object keys were silently rewritten.http pie.dev/post 007=1sent{"7": "1"}instead of{"007": "1"}, quietly dropping the leading zeros;1_000became1000and+5became5.This only treats a segment as a number when it's written in canonical integer form, keeping everything else as verbatim text. Canonical values including negative indexes like
foo[-10]are unaffected. Added coverage totest_nested_json_syntaxand a changelog entry.