FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-152052: Fix misleading `json` error for `\uXXXX` escape at the end of input (GH-152053) by miss-islington · Pull Request #152283 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions Lib/test/test_json/test_fail.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def test_truncated_input(self):
('"', 'Unterminated string starting at', 0),
('"spam', 'Unterminated string starting at', 0),
]
# A complete \uXXXX escape at end of input leaves it unterminated.
test_cases += [
(r'"\u0041', 'Unterminated string starting at', 0),
(r'"\ud834', 'Unterminated string starting at', 0),
(r'"\ud834\udd1e', 'Unterminated string starting at', 0),
(r'{"a": "\u0041', 'Unterminated string starting at', 6),
]
for data, msg, idx in test_cases:
with self.assertRaises(self.JSONDecodeError) as cm:
self.loads(data)
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_json/test_scanstring.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def test_bad_escapes(self):
'"\\ud834\\u-123"',
'"\\ud834\\u+123"',
'"\\ud834\\u1_23"',
# Truncated or non-hex \uXXXX escape at end of input.
'"\\u004',
'"\\uXYZW',
]
for s in bad_escapes:
with self.assertRaises(self.JSONDecodeError, msg=s):
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The :mod:`json` C accelerator now correctly reports an unterminated string for a
``\uXXXX`` escape at the end of the input.
2 changes: 1 addition & 1 deletion Modules/_json.c
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
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
c = 0;
next++;
end = next + 4;
if (end >= len) {
if (end > len) {
raise_errmsg("Invalid \\uXXXX escape", pystr, next - 1);
goto bail;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL