cpython: c85305a54e6d (original) (raw)

Mercurial > cpython

changeset 87587:c85305a54e6d 2.7

Issue #11489: JSON decoder now accepts lone surrogates. [#11489]

Serhiy Storchaka storchaka@gmail.com
date Tue, 26 Nov 2013 21:25:15 +0200
parents 461a4d10753a
children 72951ffbdc76 c8e138646be1
files Lib/json/decoder.py Lib/json/tests/test_scanstring.py Misc/NEWS Modules/_json.c
diffstat 4 files changed, 84 insertions(+), 57 deletions(-)[+] [-] Lib/json/decoder.py 35 Lib/json/tests/test_scanstring.py 55 Misc/NEWS 2 Modules/_json.c 49

line wrap: on

line diff

--- a/Lib/json/decoder.py +++ b/Lib/json/decoder.py @@ -62,6 +62,16 @@ BACKSLASH = { DEFAULT_ENCODING = "utf-8" +def _decode_uXXXX(s, pos):

+ def py_scanstring(s, end, encoding=None, strict=True, _b=BACKSLASH, _m=STRINGCHUNK.match): """Scan the string s for a JSON string. End is the index of the @@ -116,25 +126,16 @@ def py_scanstring(s, end, encoding=None, end += 1 else: # Unicode escape sequence

--- a/Lib/json/tests/test_scanstring.py +++ b/Lib/json/tests/test_scanstring.py @@ -5,10 +5,6 @@ from json.tests import PyTest, CTest class TestScanstring(object): def test_scanstring(self): scanstring = self.json.decoder.scanstring

- if sys.maxunicode == 65535: self.assertEqual( scanstring(u'"z\U0001d120x"', 1, None, True), @@ -94,6 +90,57 @@ class TestScanstring(object): scanstring('["Bad value", truth]', 2, None, True), (u'Bad value', 12))

+

+

+ def test_issue3623(self): self.assertRaises(ValueError, self.json.decoder.scanstring, b"xxx", 1, "xxx")

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,6 +15,8 @@ Core and Builtins Library ------- +- Issue #11489: JSON decoder now accepts lone surrogates. +

--- a/Modules/_json.c +++ b/Modules/_json.c @@ -524,16 +524,10 @@ scanstring_str(PyObject pystr, Py_ssize } #ifdef Py_UNICODE_WIDE / Surrogate pair */

@@ -554,15 +548,10 @@ scanstring_str(PyObject *pystr, Py_ssize goto bail; } }

#endif } @@ -703,16 +692,9 @@ scanstring_unicode(PyObject pystr, Py_s } #ifdef Py_UNICODE_WIDE / Surrogate pair */

@@ -733,15 +715,10 @@ scanstring_unicode(PyObject *pystr, Py_s goto bail; } }

#endif }