Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f0bf853

Browse filesBrowse files
committed
bug #38040 [Yaml Parser] fixed Parser to skip comments when inlining sequences (korve)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Yaml Parser] fixed Parser to skip comments when inlining sequences | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37972 | License | MIT The parser didn't skip comments when parsing values in a sequence. This resulted in the YamlFileLoader trying to parse a comment as a IteratorArgument which resulted in a InvalidArgumentException. Consider the following valid yaml: ```yaml - !foo [ bar, #baz ] ``` The parser would generate the following array: ```php ['bar', '#baz'] ``` After this fix the parser will generate the following array: ```php ['bar'] ``` This bug only appeared for me in 4.4 Commits ------- b5316eb [Yaml Parser] fixed Parser to skip comments when inlining sequences
2 parents 4222a72 + b5316eb commit f0bf853
Copy full SHA for f0bf853

File tree

Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed

‎src/Symfony/Component/Yaml/Parser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Parser.php
+7-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/ParserTest.php
+24Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.