diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-26 19:27:11 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-26 19:27:11 (GMT) |
commit | 687ff0ecdf9eb574c3553eee2a8492668cfa84ef (patch) | |
tree | 19e87329763348558f5e0a92b3e396f078dd6b1a /Modules | |
parent | 1df88677e96f258a917b1cec0940ea98aeccaa72 (diff) | |
parent | c93329b3dd6dde3de76f473f5573233cb0366d9c (diff) | |
download | cpython-687ff0ecdf9eb574c3553eee2a8492668cfa84ef.zip cpython-687ff0ecdf9eb574c3553eee2a8492668cfa84ef.tar.gz cpython-687ff0ecdf9eb574c3553eee2a8492668cfa84ef.tar.bz2 |
Issue #11489: JSON decoder now accepts lone surrogates.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_json.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index 301bc87..125101f 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -409,17 +409,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next } } /* Surrogate pair */ - if (Py_UNICODE_IS_HIGH_SURROGATE(c)) { + if (Py_UNICODE_IS_HIGH_SURROGATE(c) && end + 6 < len && + PyUnicode_READ(kind, buf, next++) == '\\' && + PyUnicode_READ(kind, buf, next++) == 'u') { Py_UCS4 c2 = 0; - if (end + 6 >= len) { - raise_errmsg("Unpaired high surrogate", pystr, end - 5); - goto bail; - } - if (PyUnicode_READ(kind, buf, next++) != '\\' || - PyUnicode_READ(kind, buf, next++) != 'u') { - raise_errmsg("Unpaired high surrogate", pystr, end - 5); - goto bail; - } end += 6; /* Decode 4 hex digits */ for (; next < end; next++) { @@ -440,15 +433,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next goto bail; } } - if (!Py_UNICODE_IS_LOW_SURROGATE(c2)) { - raise_errmsg("Unpaired high surrogate", pystr, end - 5); - goto bail; - } - c = Py_UNICODE_JOIN_SURROGATES(c, c2); - } - else if (Py_UNICODE_IS_LOW_SURROGATE(c)) { - raise_errmsg("Unpaired low surrogate", pystr, end - 5); - goto bail; + if (Py_UNICODE_IS_LOW_SURROGATE(c2)) + c = Py_UNICODE_JOIN_SURROGATES(c, c2); + else + end -= 6; } } APPEND_OLD_CHUNK |