fix deserializing nested arrays with implicit keys into map

This commit is contained in:
Robin Appelman 2021-08-29 20:45:45 +02:00
commit 189a19d631

View file

@ -595,6 +595,9 @@ impl<'de, 'a> MapAccess<'de> for ArrayWalker<'de, 'a> {
Token::LiteralString, Token::LiteralString,
Token::Null, Token::Null,
self.syntax.close_bracket(), self.syntax.close_bracket(),
// below is only when this token is a value with implicit key, not a when the token is a key
Token::Array,
Token::SquareOpen,
], ],
self.source(), self.source(),
)?; )?;
@ -604,13 +607,29 @@ impl<'de, 'a> MapAccess<'de> for ArrayWalker<'de, 'a> {
return Ok(None); return Ok(None);
} }
let next = self.de.next_token().expect_token( let next = self.de.next_token().ok_or_else(|| {
Option::<SpannedToken>::None
.expect_token(
&[Token::Arrow, Token::Comma, self.syntax.close_bracket()], &[Token::Arrow, Token::Comma, self.syntax.close_bracket()],
self.source(), self.source(),
)?; )
.unwrap_err()
})?;
match next.token { match next.token {
Token::Arrow => { Token::Arrow => {
// now we know it's a map key, the expected token is a bit more strict
let token = token.expect_token(
&[
Token::Bool,
Token::Integer,
Token::Float,
Token::LiteralString,
Token::Null,
self.syntax.close_bracket(),
],
self.source(),
)?;
// Deserialize a map key. // Deserialize a map key.
if let Key::Int(int_key) = self.de.parser.parse_array_key(token.clone())? { if let Key::Int(int_key) = self.de.parser.parse_array_key(token.clone())? {
self.next_int_key = int_key + 1; self.next_int_key = int_key + 1;