Skip to content

Commit bf598c9

Browse files
alexpottnicolas-grekas
authored andcommitted
[Yaml] fix inline notation with inline comment
1 parent fb4722f commit bf598c9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ private function lexInlineStructure(int &$cursor, string $closingTag, bool $cons
12061206
$value .= $this->currentLine[$cursor];
12071207
++$cursor;
12081208

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

Tests/ParserTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,19 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array
21602160
<<<YAML
21612161
map: {key: "value", a: "b"}
21622162
param: "some"
2163+
YAML
2164+
],
2165+
'mixed mapping with inline notation on one line with a comment' => [
2166+
[
2167+
'map' => [
2168+
'key' => 'value',
2169+
'a' => 'b',
2170+
],
2171+
'param' => 'some',
2172+
],
2173+
<<<YAML
2174+
map: {key: "value", a: "b"} # comment
2175+
param: "some"
21632176
YAML
21642177
],
21652178
'mixed mapping with compact inline notation on one line' => [

0 commit comments

Comments
 (0)