Skip to content

Preserve non-canonical numeric nested JSON keys#1893

Open
upuddu wants to merge 1 commit into
httpie:masterfrom
upuddu:fix-nested-json-numeric-key-normalization
Open

Preserve non-canonical numeric nested JSON keys#1893
upuddu wants to merge 1 commit into
httpie:masterfrom
upuddu:fix-nested-json-numeric-key-normalization

Conversation

@upuddu

@upuddu upuddu commented Jul 7, 2026

Copy link
Copy Markdown

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 accepts 007, 1_000, +5, and whitespace-padded values - so numeric-looking object keys were silently rewritten. http pie.dev/post 007=1 sent {"7": "1"} instead of {"007": "1"}, quietly dropping the leading zeros; 1_000 became 1000 and +5 became 5.

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 to test_nested_json_syntax and a changelog entry.

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.
@upuddu

upuddu commented Jul 8, 2026

Copy link
Copy Markdown
Author

The failing checks here are pre-existing on master (5b604c3) and unrelated to this PR, which only touches httpie/cli/nested_json/parse.py and its test:

  • test_encoding.py::test_terminal_output_*_charset_detection[big5-…] fails because current charset_normalizer (3.4.x) detects the big5 sample as EUC-KR. It also fails on unmodified master.
  • test_auth.py::test_digest_auth[https-…] fails intermittently with Context has already been used to create a Connection (urllib3/pytest-httpbin SSLContext reuse).
  • The 3.7 matrix legs fail at setup because GitHub runners no longer provide Python 3.7; the macos-13 legs time out at the runner level.

All added tests pass locally (pytest tests/test_json.py → 295 passed). Repo-level fixes for the above (dependency pins / dropping 3.7 / SSLContext test fix) belong in separate infra PRs, not here. Happy to rebase once master's CI baseline is repaired.

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.

1 participant