Skip to content

Commit

Permalink
[Yaml] Fix parsing of unquoted strings in Parser::lexUnquotedString()…
Browse files Browse the repository at this point in the history
… to ignore spaces
  • Loading branch information
Link1515 authored and xabbuh committed Jan 1, 2025
1 parent e99b4e9 commit 4eae3a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ private function lexInlineQuotedString(int &$cursor = 0): string
private function lexUnquotedString(int &$cursor): string
{
$offset = $cursor;
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
$cursor += strcspn($this->currentLine, '[]{},:', $cursor);

if ($cursor === $offset) {
throw new ParseException('Malformed unquoted YAML string.');
Expand Down
27 changes: 27 additions & 0 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,33 @@ public function testBackslashInQuotedMultiLineString()
$this->assertSame($expected, $this->parser->parse($yaml));
}

/**
* @dataProvider wrappedUnquotedStringsProvider
*/
public function testWrappedUnquotedStringWithMultipleSpacesInValue(string $yaml, array $expected)
{
$this->assertSame($expected, $this->parser->parse($yaml));
}

public static function wrappedUnquotedStringsProvider() {
return [
'mapping' => [
'{ foo: bar bar, fiz: cat cat }',
[
'foo' => 'bar bar',
'fiz' => 'cat cat',
]
],
'sequence' => [
'[ bar bar, cat cat ]',
[
'bar bar',
'cat cat',
]
],
];
}

public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT
Expand Down

0 comments on commit 4eae3a6

Please sign in to comment.