Skip to content

Commit b5316eb

Browse files
korvefabpot
authored andcommitted
[Yaml Parser] fixed Parser to skip comments when inlining sequences
1 parent 6c2a1c9 commit b5316eb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,13 @@ private function lexInlineSequence(string $yaml): string
12441244
for ($i = 1; isset($this->currentLine[$i]) && ']' !== $this->currentLine[$i]; ++$i) {
12451245
}
12461246

1247-
$value .= trim($this->currentLine);
1247+
$trimmedValue = trim($this->currentLine);
1248+
1249+
if ('' !== $trimmedValue && '#' === $trimmedValue[0]) {
1250+
continue;
1251+
}
1252+
1253+
$value .= $trimmedValue;
12481254

12491255
if (isset($this->currentLine[$i]) && ']' === $this->currentLine[$i]) {
12501256
break;

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,30 @@ public function taggedValuesProvider()
18981898
[new TaggedValue('foo', 'bar')],
18991899
'[ !foo bar ]',
19001900
],
1901+
'with-comments' => [
1902+
[
1903+
[new TaggedValue('foo', ['foo', 'baz'])],
1904+
],
1905+
<<<YAML
1906+
- [!foo [
1907+
foo,
1908+
baz
1909+
#bar
1910+
]]
1911+
YAML
1912+
],
1913+
'with-comments-trailing-comma' => [
1914+
[
1915+
[new TaggedValue('foo', ['foo', 'baz'])],
1916+
],
1917+
<<<YAML
1918+
- [!foo [
1919+
foo,
1920+
baz,
1921+
#bar
1922+
]]
1923+
YAML
1924+
],
19011925
];
19021926
}
19031927

0 commit comments

Comments
 (0)