Skip to content

Commit

Permalink
Decoder: fixed JSON parsing with \n before comma
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 28, 2024
1 parent 1e453c4 commit 8e38e87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Neon/Parser.php
Expand Up @@ -211,12 +211,12 @@ private function parseBraces(): Node\InlineArrayNode

$this->injectPos($item, $item->startTokenPos, $item->value->endTokenPos);

if ($this->tokens->consume(',', Token::Newline)) {
goto loop;
}

$old = $this->tokens->getPos();
while ($this->tokens->consume(Token::Newline));
if (!$this->tokens->isNext($endBrace)) {
$this->tokens->consume(',');
if ($old !== $this->tokens->getPos()) {
goto loop;
} elseif (!$this->tokens->isNext($endBrace)) {
$this->tokens->error();
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Neon/Decoder.inline.array.phpt
Expand Up @@ -66,3 +66,7 @@ Assert::same(

// JSON compatibility
Assert::same(['a' => true], Neon::decode('{"a":true}'));
Assert::same([1, 2], Neon::decode('[1,2]'));
Assert::same([1, 2], Neon::decode("[1\n,2]"));
Assert::same([1, 2], Neon::decode("[1,\n2]"));
Assert::same([1, 2], Neon::decode("[1\n,\n2]"));

0 comments on commit 8e38e87

Please sign in to comment.