| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…f input The C accelerator of json reported "Invalid \uXXXX escape" instead of "Unterminated string starting at" for a complete, valid \uXXXX escape whose last hex digit is the final character of the input, diverging from the pure-Python decoder. The bounds check used `>=` where `>` is correct: when end == len the four hex digits at indices len-4..len-1 are all in bounds, so the escape is valid and the string is merely unterminated.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
Sorry, something went wrong.
|
GH-152283 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
|
GH-152284 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-152285 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The C accelerator of json reported Invalid \uXXXX escape where the pure-Python decoder reported Unterminated string starting at, for a \uXXXX escape whose final hex digit is the last character of the input. The two decoders disagreed on the error class, and the C one pointed the user at a non-existent invalid escape rather than the missing closing quote.
Root cause in Modules/_json.c scanstring_unicode(): the bounds check used >= where > is correct. The four hex digits are read at indices end-4 .. end-1; when end == len those are all in bounds, so the escape is complete and valid and the string is merely unterminated. Changing >= to > lets control fall through to the existing Unterminated string starting at path, matching the pure-Python decoder (the two json error messages were synchronized in bpo-5067).
Tests cover both decoders: test_fail.py::test_truncated_input asserts the exact message/position under TestCFail and TestPyFail (including a high surrogate and a surrogate pair at EOF, and a nested non-zero offset), and test_scanstring.py::test_bad_escapes gains two no-regression cases (a genuinely truncated escape and four non-hex chars at EOF) confirming the change does not weaken rejection of real invalid escapes.
Fixes #152052