mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-113149: Improve error message when JSON has trailing comma (GH-113227)
This commit is contained in:
parent
21d52995ea
commit
cfa25fe3e3
4 changed files with 28 additions and 3 deletions
|
@ -662,6 +662,7 @@ _parse_object_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ss
|
|||
PyObject *key = NULL;
|
||||
int has_pairs_hook = (s->object_pairs_hook != Py_None);
|
||||
Py_ssize_t next_idx;
|
||||
Py_ssize_t comma_idx;
|
||||
|
||||
str = PyUnicode_DATA(pystr);
|
||||
kind = PyUnicode_KIND(pystr);
|
||||
|
@ -741,10 +742,16 @@ _parse_object_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ss
|
|||
raise_errmsg("Expecting ',' delimiter", pystr, idx);
|
||||
goto bail;
|
||||
}
|
||||
comma_idx = idx;
|
||||
idx++;
|
||||
|
||||
/* skip whitespace after , delimiter */
|
||||
while (idx <= end_idx && IS_WHITESPACE(PyUnicode_READ(kind, str, idx))) idx++;
|
||||
|
||||
if (idx <= end_idx && PyUnicode_READ(kind, str, idx) == '}') {
|
||||
raise_errmsg("Illegal trailing comma before end of object", pystr, comma_idx);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -785,6 +792,7 @@ _parse_array_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ssi
|
|||
PyObject *val = NULL;
|
||||
PyObject *rval;
|
||||
Py_ssize_t next_idx;
|
||||
Py_ssize_t comma_idx;
|
||||
|
||||
rval = PyList_New(0);
|
||||
if (rval == NULL)
|
||||
|
@ -822,10 +830,16 @@ _parse_array_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ssi
|
|||
raise_errmsg("Expecting ',' delimiter", pystr, idx);
|
||||
goto bail;
|
||||
}
|
||||
comma_idx = idx;
|
||||
idx++;
|
||||
|
||||
/* skip whitespace after , */
|
||||
while (idx <= end_idx && IS_WHITESPACE(PyUnicode_READ(kind, str, idx))) idx++;
|
||||
|
||||
if (idx <= end_idx && PyUnicode_READ(kind, str, idx) == ']') {
|
||||
raise_errmsg("Illegal trailing comma before end of array", pystr, comma_idx);
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue