diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-26 19:25:28 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-26 19:25:28 (GMT) |
commit | c93329b3dd6dde3de76f473f5573233cb0366d9c (patch) | |
tree | 1dba9aa32ec2384766f56c49ffd4887c3e47bd13 /Modules/_json.c | |
parent | f45bbb62110a7bbcbbf45c1a52be6de7b791b189 (diff) | |
download | cpython-c93329b3dd6dde3de76f473f5573233cb0366d9c.zip cpython-c93329b3dd6dde3de76f473f5573233cb0366d9c.tar.gz cpython-c93329b3dd6dde3de76f473f5573233cb0366d9c.tar.bz2 |
Issue #11489: JSON decoder now accepts lone surrogates.
Diffstat (limited to 'Modules/_json.c')
-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 db45c28..9166680 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -433,17 +433,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next } } /* Surrogate pair */ - if ((c & 0xfc00) == 0xd800) { + 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++) { @@ -464,15 +457,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next goto bail; } } - if ((c2 & 0xfc00) != 0xdc00) { - raise_errmsg("Unpaired high surrogate", pystr, end - 5); - goto bail; - } - c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00)); - } - else if ((c & 0xfc00) == 0xdc00) { - 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 |