gh-113149: Improve error message when JSON has trailing comma (GH-113227)

This commit is contained in:
Carson Radtke 2023-12-17 12:52:26 -06:00 committed by GitHub
parent 21d52995ea
commit cfa25fe3e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 3 deletions

View file

@ -143,11 +143,11 @@ class TestFail:
('{"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),
@ -159,7 +159,9 @@ class TestFail:
('[{"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: