mirror of
https://github.com/serde-rs/json.git
synced 2025-10-02 15:26:00 +00:00
change error type for trailing commas, fixes #352
This commit is contained in:
parent
764e9607cf
commit
4afb61cc02
@ -1062,6 +1062,7 @@ impl<'de, 'a, R: Read<'de> + 'a> de::MapAccess<'de> for MapAccess<'a, R> {
|
||||
|
||||
match peek {
|
||||
Some(b'"') => seed.deserialize(MapKey { de: &mut *self.de }).map(Some),
|
||||
Some(b'}') => Err(self.de.peek_error(ErrorCode::TrailingCharacters)),
|
||||
Some(_) => Err(self.de.peek_error(ErrorCode::KeyMustBeAString)),
|
||||
None => Err(self.de.peek_error(ErrorCode::EofWhileParsingValue)),
|
||||
}
|
||||
|
@ -1114,6 +1114,11 @@ fn test_parse_enum_errors() {
|
||||
("{\"Cat\":[0, \"\", 2]}", "trailing characters at line 1 column 14"),
|
||||
("{\"Cat\":{\"age\": 5, \"name\": \"Kate\", \"foo\":\"bar\"}",
|
||||
"unknown field `foo`, expected `age` or `name` at line 1 column 39"),
|
||||
|
||||
// JSON does not allow trailing commas in data structures
|
||||
("{\"Cat\":[0, \"Kate\",]}", "trailing characters at line 1 column 18"),
|
||||
("{\"Cat\":{\"age\": 2, \"name\": \"Kate\",}}",
|
||||
"trailing characters at line 1 column 34"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user