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 Jun 26, 2024
1 parent b2b28ae commit 0d31534
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 0d31534

Please sign in to comment.