8000 [Yaml] Fix parsing of unquoted strings in Parser::lexUnquotedString()… · symfony/symfony@dc8898a · GitHub
[go: up one dir, main page]

Skip to content

Commit dc8898a

Browse files
Link1515xabbuh
authored andcommitted
[Yaml] Fix parsing of unquoted strings in Parser::lexUnquotedString() to ignore spaces
1 parent c2cc75d commit dc8898a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ private function lexInlineQuotedString(int &$cursor = 0): string
11581158
private function lexUnquotedString(int &$cursor): string
11591159
{
11601160
$offset = $cursor;
1161-
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
1161+
$cursor += strcspn($this->currentLine, '[]{},:', $cursor);
11621162

11631163
if ($cursor === $offset) {
11641164
throw new ParseException('Malformed unquoted YAML string.');

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,33 @@ public function testBackslashInQuotedMultiLineString()
17101710
$this->assertSame($expected, $this->parser->parse($yaml));
17111711
}
17121712

1713+
/**
1714+
* @dataProvider wrappedUnquotedStringsProvider
1715+
*/
1716+
public function testWrappedUnquotedStringWithMultipleSpacesInValue(string $yaml, array $expected)
1717+
{
1718+
$this->assertSame($expected, $this->parser->parse($yaml));
1719+
}
1720+
1721+
public static function wrappedUnquotedStringsProvider() {
1722+
return [
1723+
'mapping' => [
1724+
'{ foo: bar bar, fiz: cat cat }',
1725+
[
1726+
'foo' => 'bar bar',
1727+
'fiz' => 'cat cat',
1728+
]
1729+
],
1730+
'sequence' => [
1731+
'[ bar bar, cat cat ]',
1732+
[
1733+
'bar bar',
1734+
'cat cat',
1735+
]
1736+
],
1737+
];
1738+
}
1739+
17131740
public function testParseMultiLineUnquotedString()
17141741
{
17151742
$yaml = <<<EOT

0 commit comments

Comments
 (0)
0