summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-10-18 12:26:29 (GMT)
committerGitHub <noreply@github.com>2024-10-18 12:26:29 (GMT)
commitd358425e6968858e52908794d15f37e62abc74ec (patch)
tree309384b237287d58261ea7f7d5b0a054b35afc24
parenta0f5c8e6272a1fd5422892d773923b138e77ae5f (diff)
downloadcpython-d358425e6968858e52908794d15f37e62abc74ec.zip
cpython-d358425e6968858e52908794d15f37e62abc74ec.tar.gz
cpython-d358425e6968858e52908794d15f37e62abc74ec.tar.bz2
gh-125682: Reject non-ASCII digits in the Python implementation of JSON decoder (GH-125687)
-rw-r--r--Lib/json/scanner.py2
-rw-r--r--Lib/test/test_json/test_decode.py6
-rw-r--r--Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst2
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py
index 7a61cfc..0908975 100644
--- a/Lib/json/scanner.py
+++ b/Lib/json/scanner.py
@@ -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):
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py
index 79fb239..2250af9 100644
--- a/Lib/test/test_json/test_decode.py
+++ b/Lib/test/test_json/test_decode.py
@@ -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
index 0000000..3eb2905
--- /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.