Skip to content

Commit fb61e7d

Browse files
committed
[Yaml] Align unquoted multiline scalar parsing with spec for comments
1 parent d398686 commit fb61e7d

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ private function parseValue(string $value, int $flags, string $context): mixed
775775
}
776776

777777
if ($this->isCurrentLineComment()) {
778-
continue;
778+
break;
779779
}
780780

781781
$lines[] = trim($this->currentLine);

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,35 +1752,32 @@ public function testParseMultiLineUnquotedString()
17521752
}
17531753

17541754
/**
1755-
* @dataProvider getUnquotedMultilineScalarIgnoresCommentsData
1755+
* @dataProvider getUnquotedMultilineScalarHandlesCommentsAndBlanksData
17561756
*/
1757-
public function testUnquotedMultilineScalarIgnoresComments(string $yaml, array $expected)
1757+
public function testUnquotedMultilineScalarHandlesCommentsAndBlanks(string $yaml, array $expected)
17581758
{
17591759
$this->assertSame($expected, $this->parser->parse($yaml));
17601760
}
17611761

1762-
public static function getUnquotedMultilineScalarIgnoresCommentsData()
1762+
public static function getUnquotedMultilineScalarHandlesCommentsAndBlanksData()
17631763
{
1764-
yield 'comments interspersed' => [
1764+
yield 'comments interspersed stops scalar' => [
17651765
<<<YAML
17661766
key: unquoted
1767-
# this comment should be ignored
1768-
next line
1769-
# another comment
1770-
final line
1767+
# this comment terminates
17711768
another_key: works
17721769
YAML,
17731770
[
1774-
'key' => 'unquoted next line final line',
1771+
'key' => 'unquoted',
17751772
'another_key' => 'works',
17761773
],
17771774
];
17781775

17791776
yield 'only comments' => [
17801777
<<<YAML
17811778
key: unquoted
1782-
# this comment should be ignored
1783-
# another comment
1779+
# this comment terminates
1780+
# this is just another comment
17841781
another_key: works
17851782
YAML,
17861783
[
@@ -1789,26 +1786,25 @@ public static function getUnquotedMultilineScalarIgnoresCommentsData()
17891786
],
17901787
];
17911788

1792-
yield 'blank lines and comments' => [
1789+
yield 'blank lines are preserved and comment stops scalar' => [
17931790
<<<YAML
17941791
key: unquoted
1795-
next line
1792+
next line
17961793
1797-
# this comment should be ignored
1798-
final line
1794+
# this comment terminates the scalar
17991795
another_key: works
18001796
YAML,
18011797
[
1802-
'key' => "unquoted next line\nfinal line",
1798+
'key' => 'unquoted next line',
18031799
'another_key' => 'works',
18041800
],
18051801
];
18061802

1807-
yield 'comment at end' => [
1803+
yield 'comment at end stops scalar' => [
18081804
<<<YAML
18091805
key: unquoted
1810-
next line
1811-
# comment at end
1806+
next line
1807+
# comment at end
18121808
another_key: works
18131809
YAML,
18141810
[

0 commit comments

Comments
 (0)