https://github.com/python/cpython/commit/6715afe349a2e39d9f3eef0c655faecb0db93f3b
commit: 6715afe349a2e39d9f3eef0c655faecb0db93f3b
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-10-21T16:06:31+03:00
summary:

[3.13] gh-125682: Reject non-ASCII digits in the Python implementation of JSON 
decoder (GH-125687) (GH-125692)

(cherry picked from commit d358425e6968858e52908794d15f37e62abc74ec)

Co-authored-by: Nice Zombies <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst
M Lib/json/scanner.py
M Lib/test/test_json/test_decode.py

diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py
index 7a61cfc2d24dce..090897515fe2f3 100644
--- a/Lib/json/scanner.py
+++ b/Lib/json/scanner.py
@@ -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):
diff --git a/Lib/test/test_json/test_decode.py 
b/Lib/test/test_json/test_decode.py
index 79fb239b35d3f2..2250af964c022b 100644
--- a/Lib/test/test_json/test_decode.py
+++ b/Lib/test/test_json/test_decode.py
@@ -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)
 
diff --git 
a/Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst 
b/Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst
new file mode 100644
index 00000000000000..3eb2905ad8d810
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst
@@ -0,0 +1,2 @@
+Reject non-ASCII digits in the Python implementation of :func:`json.loads`
+conforming to the JSON specification.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to