]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-125682: Reject non-ASCII digits in the Python implementation of JSON decoder ...
authorNice Zombies <nineteendo19d0@gmail.com>
Fri, 18 Oct 2024 12:26:29 +0000 (14:26 +0200)
committerGitHub <noreply@github.com>
Fri, 18 Oct 2024 12:26:29 +0000 (15:26 +0300)
Lib/json/scanner.py
Lib/test/test_json/test_decode.py
Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst [new file with mode: 0644]

index 7a61cfc2d24dceb3530988884f70f51f398d5855..090897515fe2f3818767a6dcf7b2310dca2c850a 100644 (file)
@@ -9,7 +9,7 @@ except ImportError:
 __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):
index 79fb239b35d3f2e3df568f38675aa573024c369f..2250af964c022bf4fc3d95ee2238502e7fe0b51b 100644 (file)
@@ -16,6 +16,12 @@ class TestDecode:
         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 (file)
index 0000000..3eb2905
--- /dev/null
@@ -0,0 +1,2 @@
+Reject non-ASCII digits in the Python implementation of :func:`json.loads`
+conforming to the JSON specification.