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
|
@ -200,10 +200,13 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
|
|||
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:
|
||||
|
@ -240,13 +243,17 @@ def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
|
|||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue