Skip to content

Commit

Permalink
[Yaml] fix inline notation with inline comment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpott authored and nicolas-grekas committed Jan 7, 2025
1 parent 9590658 commit dccac0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ private function lexInlineStructure(int &$cursor, string $closingTag, bool $cons
$value .= $this->currentLine[$cursor];
++$cursor;

if ($consumeUntilEol && isset($this->currentLine[$cursor]) && (strspn($this->currentLine, ' ', $cursor) + $cursor) < strlen($this->currentLine)) {
if ($consumeUntilEol && isset($this->currentLine[$cursor]) && ($whitespaces = strspn($this->currentLine, ' ', $cursor) + $cursor) < strlen($this->currentLine) && '#' !== $this->currentLine[$whitespaces]) {
throw new ParseException(sprintf('Unexpected token "%s".', trim(substr($this->currentLine, $cursor))));
}

Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,19 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array
<<<YAML
map: {key: "value", a: "b"}
param: "some"
YAML
],
'mixed mapping with inline notation on one line with a comment' => [
[
'map' => [
'key' => 'value',
'a' => 'b',
],
'param' => 'some',
],
<<<YAML
map: {key: "value", a: "b"} # comment
param: "some"
YAML
],
'mixed mapping with compact inline notation on one line' => [
Expand Down

0 comments on commit dccac0b

Please sign in to comment.