change error type for trailing commas, fixes #352

This commit is contained in:
fmoor 2017-09-01 11:32:32 -07:00
parent 764e9607cf
commit 4afb61cc02
2 changed files with 6 additions and 0 deletions

View File

@ -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)),
}

View File

@ -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"),
],
);
}