Skip to content

Commit

Permalink
gh-125682: Reject non-ASCII digits in the Python implementation of JS…
Browse files Browse the repository at this point in the history
…ON decoder (GH-125687)
  • Loading branch information
nineteendo authored Oct 18, 2024
1 parent a0f5c8e commit d358425
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/json/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__all__ = ['make_scanner']

NUMBER_RE = re.compile(
r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
r'(-?(?:0|[1-9][0-9]*))(\.[0-9]+)?([eE][-+]?[0-9]+)?',
(re.VERBOSE | re.MULTILINE | re.DOTALL))

def py_make_scanner(context):
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_json/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def test_float(self):
self.assertIsInstance(rval, float)
self.assertEqual(rval, 1.0)

def test_nonascii_digits_rejected(self):
# JSON specifies only ascii digits, see gh-125687
for num in ["1\uff10", "0.\uff10", "0e\uff10"]:
with self.assertRaises(self.JSONDecodeError):
self.loads(num)

def test_bytes(self):
self.assertEqual(self.loads(b"1"), 1)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Reject non-ASCII digits in the Python implementation of :func:`json.loads`
conforming to the JSON specification.

0 comments on commit d358425

Please sign in to comment.