summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-11-26 19:25:15 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-11-26 19:25:15 (GMT)
commitdafda9b042cb8a53e59a8d33a75692795097f154 (patch)
tree667a88defb1e935c290ac77ee0dc63bd22fd39ff /Modules/_json.c
parent60e361fe4209a418f1ba325fe69a9bdae1a5b831 (diff)
downloadcpython-dafda9b042cb8a53e59a8d33a75692795097f154.zip
cpython-dafda9b042cb8a53e59a8d33a75692795097f154.tar.gz
cpython-dafda9b042cb8a53e59a8d33a75692795097f154.tar.bz2
Issue #11489: JSON decoder now accepts lone surrogates.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c49
1 files changed, 13 insertions, 36 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 13f5816..eb4368a 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -524,16 +524,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s
}
#ifdef Py_UNICODE_WIDE
/* Surrogate pair */
- if ((c & 0xfc00) == 0xd800) {
+ if ((c & 0xfc00) == 0xd800 && end + 6 < len &&
+ buf[next++] == '\\' &&
+ buf[next++] == 'u') {
Py_UNICODE c2 = 0;
- if (end + 6 >= len) {
- raise_errmsg("Unpaired high surrogate", pystr, end - 5);
- goto bail;
- }
- if (buf[next++] != '\\' || buf[next++] != 'u') {
- raise_errmsg("Unpaired high surrogate", pystr, end - 5);
- goto bail;
- }
end += 6;
/* Decode 4 hex digits */
for (; next < end; next++) {
@@ -554,15 +548,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s
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 ((c2 & 0xfc00) == 0xdc00)
+ c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00));
+ else
+ end -= 6;
}
#endif
}
@@ -703,16 +692,9 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
}
#ifdef Py_UNICODE_WIDE
/* Surrogate pair */
- if ((c & 0xfc00) == 0xd800) {
+ if ((c & 0xfc00) == 0xd800 && end + 6 < len &&
+ buf[next++] == '\\' && buf[next++] == 'u') {
Py_UNICODE c2 = 0;
- if (end + 6 >= len) {
- raise_errmsg("Unpaired high surrogate", pystr, end - 5);
- goto bail;
- }
- if (buf[next++] != '\\' || buf[next++] != 'u') {
- raise_errmsg("Unpaired high surrogate", pystr, end - 5);
- goto bail;
- }
end += 6;
/* Decode 4 hex digits */
for (; next < end; next++) {
@@ -733,15 +715,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 ((c2 & 0xfc00) == 0xdc00)
+ c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00));
+ else
+ end -= 6;
}
#endif
}