Skip to content
/ yaml Public

Commit 74521d9

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Translation] Make the extractor alias optional [Cache] Fix accepting named closures as early-expiration callbacks [Mime] Update mime types [HttpKernel] Conflict with symfony/flex < 2.10 [Yaml] Align unquoted multiline scalar parsing with spec for comments work around limitation in JsonResponse when the data is null do not use recipient phone numbers as sender e-mail addresses [Dotenv] DotenvDumpCommand cannot be internal
2 parents b5479b7 + 6c84a4b commit 74521d9

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

Parser.php

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

784784
if ($this->isCurrentLineComment()) {
785-
continue;
785+
break;
786786
}
787787

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

Tests/ParserTest.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,25 +1756,22 @@ public function testParseMultiLineUnquotedString()
17561756
$this->assertSame(['foo' => 'bar baz foobar foo', 'bar' => 'baz'], $this->parser->parse($yaml));
17571757
}
17581758

1759-
#[DataProvider('unquotedStringWithTrailingComment')]
1760-
public function testUnquotedMultilineScalarIgnoresComments(string $yaml, array $expected)
1759+
#[DataProvider('getUnquotedMultilineScalarHandlesCommentsAndBlanksData')]
1760+
public function testUnquotedMultilineScalarHandlesCommentsAndBlanks(string $yaml, array $expected)
17611761
{
17621762
$this->assertSame($expected, $this->parser->parse($yaml));
17631763
}
17641764

1765-
public static function getUnquotedMultilineScalarIgnoresCommentsData()
1765+
public static function getUnquotedMultilineScalarHandlesCommentsAndBlanksData()
17661766
{
1767-
yield 'comments interspersed' => [
1767+
yield 'comments interspersed stops scalar' => [
17681768
<<<YAML
17691769
key: unquoted
1770-
# this comment should be ignored
1771-
next line
1772-
# another comment
1773-
final line
1770+
# this comment terminates
17741771
another_key: works
17751772
YAML,
17761773
[
1777-
'key' => 'unquoted next line final line',
1774+
'key' => 'unquoted',
17781775
'another_key' => 'works',
17791776
],
17801777
];
@@ -1792,17 +1789,16 @@ public static function getUnquotedMultilineScalarIgnoresCommentsData()
17921789
],
17931790
];
17941791

1795-
yield 'blank lines and comments' => [
1792+
yield 'blank lines are preserved and comment stops scalar' => [
17961793
<<<YAML
17971794
key: unquoted
17981795
next line
17991796
1800-
# this comment should be ignored
1801-
final line
1797+
# this comment terminates the scalar
18021798
another_key: works
18031799
YAML,
18041800
[
1805-
'key' => "unquoted next line\nfinal line",
1801+
'key' => 'unquoted next line',
18061802
'another_key' => 'works',
18071803
],
18081804
];
@@ -1821,6 +1817,21 @@ public static function getUnquotedMultilineScalarIgnoresCommentsData()
18211817
];
18221818
}
18231819

1820+
public function testUnquotedMultilineScalarThrowsOnOrphanedLineAfterComment()
1821+
{
1822+
$this->expectException(ParseException::class);
1823+
$this->expectExceptionMessage('Unable to parse at line 3 (near " next line")');
1824+
1825+
$yaml = <<<YAML
1826+
key: unquoted
1827+
# this comment terminates
1828+
next line
1829+
another_key: works
1830+
YAML;
1831+
1832+
$this->parser->parse($yaml);
1833+
}
1834+
18241835
#[DataProvider('unquotedStringWithTrailingComment')]
18251836
public function testParseMultiLineUnquotedStringWithTrailingComment(string $yaml, array $expected)
18261837
{

0 commit comments

Comments
 (0)