mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 18:44:07 +02:00
fix deserializing nested arrays with implicit keys into map
This commit is contained in:
parent
097ed69b9e
commit
189a19d631
1 changed files with 23 additions and 4 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue