From 940c0204b9dec2b58df929736db393802ba45c8d Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Fri, 18 Oct 2024 11:12:44 +0200 Subject: [PATCH 1/6] Reject unicode digits for Python implementation of json.loads() --- Lib/json/scanner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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): From d9da606b2e29756adf03b07e3a7ae331c401197d Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Fri, 18 Oct 2024 11:45:10 +0200 Subject: [PATCH 2/6] Add tests --- Lib/test/test_json/test_decode.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py index 79fb239b35d3f2..e31114d64a5fab 100644 --- a/Lib/test/test_json/test_decode.py +++ b/Lib/test/test_json/test_decode.py @@ -16,6 +16,11 @@ def test_float(self): self.assertIsInstance(rval, float) self.assertEqual(rval, 1.0) + def test_unicode_digits(self): + 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) From e14ea8452bdef366b7ddfd71a49cf2e2c87e732e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:51:30 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst 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..4182d5b8f3102a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst @@ -0,0 +1 @@ +Reject unicode digits for Python implementation of :func:`json.loads`. From 10923b260a03498d94d4488e9048b1d6c664aa8a Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Fri, 18 Oct 2024 13:21:41 +0200 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Tal Einat <532281+taleinat@users.noreply.github.com> --- Lib/test/test_json/test_decode.py | 2 +- .../next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py index e31114d64a5fab..543a6a534bf14d 100644 --- a/Lib/test/test_json/test_decode.py +++ b/Lib/test/test_json/test_decode.py @@ -16,7 +16,7 @@ def test_float(self): self.assertIsInstance(rval, float) self.assertEqual(rval, 1.0) - def test_unicode_digits(self): + def test_nonascii_digits_rejected(self): for num in ["1\uff10", "0.\uff10", "0e\uff10"]: with self.assertRaises(self.JSONDecodeError): self.loads(num) 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 index 4182d5b8f3102a..74fd15206dc562 100644 --- 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 @@ -1 +1 @@ -Reject unicode digits for Python implementation of :func:`json.loads`. +Reject non-ASCII digits in the Python implementation of :func:`json.loads`. From 905ab94d5fb706e3378c2b52b05e0b60539b15da Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Fri, 18 Oct 2024 13:34:07 +0200 Subject: [PATCH 5/6] Link to github issue --- Lib/test/test_json/test_decode.py | 1 + .../Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py index 543a6a534bf14d..2250af964c022b 100644 --- a/Lib/test/test_json/test_decode.py +++ b/Lib/test/test_json/test_decode.py @@ -17,6 +17,7 @@ def test_float(self): 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) 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 index 74fd15206dc562..7b9f9f0806d086 100644 --- 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 @@ -1 +1,2 @@ -Reject non-ASCII digits in the Python implementation of :func:`json.loads`. +Reject non-ASCII digits in the Python implementation of :func:`json.loads` +conforming to the json specification. From 9b50c0945447051ab9a646a23d78e3cdac42f0d2 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Fri, 18 Oct 2024 13:38:24 +0200 Subject: [PATCH 6/6] Update Misc/NEWS.d/next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst Co-authored-by: Peter Bierma --- .../next/Library/2024-10-18-09-51-29.gh-issue-125682.vsj4cU.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 7b9f9f0806d086..3eb2905ad8d810 100644 --- 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 @@ -1,2 +1,2 @@ Reject non-ASCII digits in the Python implementation of :func:`json.loads` -conforming to the json specification. +conforming to the JSON specification.