Skip to content
/ yaml Public

Commit b5479b7

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: (22 commits) Fix Warning: curl_multi_select(): timeout must be positive [PropertyInfo] Fix ReflectionExtractor handling of underscore-only property names ObjectNormalizer: allow null and scalar [Security] Fix `HttpUtils::createRequest()` when the context’s base URL isn’t empty [Serializer] fix Inherited properties normalization [OptionsResolver] Fix missing prototype key in nested error paths Bump Symfony version to 7.3.8 Update VERSION for 7.3.7 Update CHANGELOG for 7.3.7 Bump Symfony version to 6.4.30 Update VERSION for 6.4.29 Update CHANGELOG for 6.4.29 [FrameworkBundle] Update deprecation message for collect_serializer_data run test using a read-only directory on Windows too [Yaml] Fix parsing of unquoted multiline scalars with comments or blank lines [Clock] Align MockClock::sleep() behavior with NativeClock for negative values [OptionsResolver] Ensure remove() also unsets deprecation status Remove review state for Belarusian translations (entries 141 and 142) [ExpressionLanguage] Compile numbers with var_export in Compiler::repr for thread-safety compatibility with ext-redis 6.3 ...
2 parents 2346745 + c082fdb commit b5479b7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Parser.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,22 @@ private function parseValue(string $value, int $flags, string $context): mixed
769769
$lines = [];
770770

771771
while ($this->moveToNextLine()) {
772+
if ($this->isCurrentLineBlank()) {
773+
$lines[] = '';
774+
continue;
775+
}
776+
772777
// unquoted strings end before the first unindented line
773778
if (0 === $this->getCurrentLineIndentation()) {
774779
$this->moveToPreviousLine();
775780

776781
break;
777782
}
778783

784+
if ($this->isCurrentLineComment()) {
785+
continue;
786+
}
787+
779788
$lines[] = trim($this->currentLine);
780789
}
781790

Tests/ParserTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,71 @@ 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)
1761+
{
1762+
$this->assertSame($expected, $this->parser->parse($yaml));
1763+
}
1764+
1765+
public static function getUnquotedMultilineScalarIgnoresCommentsData()
1766+
{
1767+
yield 'comments interspersed' => [
1768+
<<<YAML
1769+
key: unquoted
1770+
# this comment should be ignored
1771+
next line
1772+
# another comment
1773+
final line
1774+
another_key: works
1775+
YAML,
1776+
[
1777+
'key' => 'unquoted next line final line',
1778+
'another_key' => 'works',
1779+
],
1780+
];
1781+
1782+
yield 'only comments' => [
1783+
<<<YAML
1784+
key: unquoted
1785+
# this comment should be ignored
1786+
# another comment
1787+
another_key: works
1788+
YAML,
1789+
[
1790+
'key' => 'unquoted',
1791+
'another_key' => 'works',
1792+
],
1793+
];
1794+
1795+
yield 'blank lines and comments' => [
1796+
<<<YAML
1797+
key: unquoted
1798+
next line
1799+
1800+
# this comment should be ignored
1801+
final line
1802+
another_key: works
1803+
YAML,
1804+
[
1805+
'key' => "unquoted next line\nfinal line",
1806+
'another_key' => 'works',
1807+
],
1808+
];
1809+
1810+
yield 'comment at end' => [
1811+
<<<YAML
1812+
key: unquoted
1813+
next line
1814+
# comment at end
1815+
another_key: works
1816+
YAML,
1817+
[
1818+
'key' => 'unquoted next line',
1819+
'another_key' => 'works',
1820+
],
1821+
];
1822+
}
1823+
17591824
#[DataProvider('unquotedStringWithTrailingComment')]
17601825
public function testParseMultiLineUnquotedStringWithTrailingComment(string $yaml, array $expected)
17611826
{

0 commit comments

Comments
 (0)