Skip to content

Commit cf9c6b6

Browse files
Add regression test for invalid \uXXXX escape position
1 parent 30c0bfc commit cf9c6b6

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

extra_tests/snippets/stdlib_json.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,19 @@ class Dict(dict):
239239
RecursionError,
240240
lambda: json.loads(('[{"x":' * _deep) + "1" + ("}]" * _deep)),
241241
)
242+
243+
244+
# Invalid \uXXXX escape: error position points at the 'u', matching CPython.
245+
try:
246+
json.loads('"\\uXYZW"')
247+
except json.JSONDecodeError as e:
248+
assert e.pos == 2, f"expected pos=2, got {e.pos}"
249+
else:
250+
assert False, "expected JSONDecodeError"
251+
252+
try:
253+
json.loads('"abc\\uZZZZ"')
254+
except json.JSONDecodeError as e:
255+
assert e.pos == 5, f"expected pos=5, got {e.pos}"
256+
else:
257+
assert False, "expected JSONDecodeError"

0 commit comments

Comments
 (0)