Skip to content

Commit d358425

Browse files
authored
gh-125682: Reject non-ASCII digits in the Python implementation of JSON decoder (GH-125687)
1 parent a0f5c8e commit d358425

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/json/scanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__all__ = ['make_scanner']
1010

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

1515
def py_make_scanner(context):

Lib/test/test_json/test_decode.py

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def test_float(self):
1616
self.assertIsInstance(rval, float)
1717
self.assertEqual(rval, 1.0)
1818

19+
def test_nonascii_digits_rejected(self):
20+
# JSON specifies only ascii digits, see gh-125687
21+
for num in ["1\uff10", "0.\uff10", "0e\uff10"]:
22+
with self.assertRaises(self.JSONDecodeError):
23+
self.loads(num)
24+
1925
def test_bytes(self):
2026
self.assertEqual(self.loads(b"1"), 1)
2127

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

0 commit comments

Comments
 (0)