break
elif nextchar != ',':
raise JSONDecodeError("Expecting ',' delimiter", s, end - 1)
+ comma_idx = end - 1
end = _w(s, end).end()
nextchar = s[end:end + 1]
end += 1
if nextchar != '"':
+ if nextchar == '}':
+ raise JSONDecodeError("Illegal trailing comma before end of object", s, comma_idx)
raise JSONDecodeError(
"Expecting property name enclosed in double quotes", s, end - 1)
if object_pairs_hook is not None:
break
elif nextchar != ',':
raise JSONDecodeError("Expecting ',' delimiter", s, end - 1)
+ comma_idx = end - 1
try:
if s[end] in _ws:
end += 1
if s[end] in _ws:
end = _w(s, end + 1).end()
+ nextchar = s[end:end + 1]
except IndexError:
pass
+ if nextchar == ']':
+ raise JSONDecodeError("Illegal trailing comma before end of array", s, comma_idx)
return values, end
('{"spam":[}', 'Expecting value', 9),
('[42:', "Expecting ',' delimiter", 3),
('[42 "spam"', "Expecting ',' delimiter", 4),
- ('[42,]', 'Expecting value', 4),
+ ('[42,]', "Illegal trailing comma before end of array", 3),
('{"spam":[42}', "Expecting ',' delimiter", 11),
('["]', 'Unterminated string starting at', 1),
('["spam":', "Expecting ',' delimiter", 7),
- ('["spam",]', 'Expecting value', 8),
+ ('["spam",]', "Illegal trailing comma before end of array", 7),
('{:', 'Expecting property name enclosed in double quotes', 1),
('{,', 'Expecting property name enclosed in double quotes', 1),
('{42', 'Expecting property name enclosed in double quotes', 1),
('[{"spam":]', 'Expecting value', 9),
('{"spam":42 "ham"', "Expecting ',' delimiter", 11),
('[{"spam":42]', "Expecting ',' delimiter", 11),
- ('{"spam":42,}', 'Expecting property name enclosed in double quotes', 11),
+ ('{"spam":42,}', "Illegal trailing comma before end of object", 10),
+ ('{"spam":42 , }', "Illegal trailing comma before end of object", 11),
+ ('[123 , ]', "Illegal trailing comma before end of array", 6),
]
for data, msg, idx in test_cases:
with self.assertRaises(self.JSONDecodeError) as cm:
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);
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;
+ }
}
}
PyObject *val = NULL;
PyObject *rval;
Py_ssize_t next_idx;
+ Py_ssize_t comma_idx;
rval = PyList_New(0);
if (rval == NULL)
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;
+ }
}
}