Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4: (23 commits)
  add translations for the Slug constraint
  [Messenger] Fix `TransportMessageIdStamp` not always added
  [DoctrineBridge] Fix compatibility to Doctrine persistence 2.5 in Doctrine Bridge 6.4 to avoid Projects stuck on 6.3
  [PropertyInfo] Fix add missing composer conflict
  [ErrorHandler] Don't trigger "internal" deprecations for anonymous LazyClosure instances
  [VarDumper] Fix displaying closure's "this" from anonymous classes
  [Doctrine][Messenger] Prevents multiple TransportMessageIdStamp being stored in envelope
  [HttpKernel] Don't override existing LoggerInterface autowiring alias in LoggerPass
  reject inline notations followed by invalid content
  [Security] Fix triggering session tracking from ContextListener
  [AssetMapper] add leading slash to public prefix
  fix: modify Exception message parameter order
  [Yaml] Fix parsing of unquoted strings in Parser::lexUnquotedString() to ignore spaces
  Update exception.css
  Bump Symfony version to 6.4.18
  Update VERSION for 6.4.17
  Update CONTRIBUTORS for 6.4.17
  Update CHANGELOG for 6.4.17
  Fix exception thrown by YamlEncoder
  [AssetMapper] Fix JavaScript compiler create self-referencing imports
  ...
  • Loading branch information
xabbuh committed Jan 7, 2025
2 parents 3ced3f2 + fb4722f commit ff52a85
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,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 All @@ -1162,17 +1162,17 @@ private function lexUnquotedString(int &$cursor): string
return substr($this->currentLine, $offset, $cursor - $offset);
}

private function lexInlineMapping(int &$cursor = 0): string
private function lexInlineMapping(int &$cursor = 0, bool $consumeUntilEol = true): string
{
return $this->lexInlineStructure($cursor, '}');
return $this->lexInlineStructure($cursor, '}', $consumeUntilEol);
}

private function lexInlineSequence(int &$cursor = 0): string
private function lexInlineSequence(int &$cursor = 0, bool $consumeUntilEol = true): string
{
return $this->lexInlineStructure($cursor, ']');
return $this->lexInlineStructure($cursor, ']', $consumeUntilEol);
}

private function lexInlineStructure(int &$cursor, string $closingTag): string
private function lexInlineStructure(int &$cursor, string $closingTag, bool $consumeUntilEol = true): string
{
$value = $this->currentLine[$cursor];
++$cursor;
Expand All @@ -1192,15 +1192,19 @@ private function lexInlineStructure(int &$cursor, string $closingTag): string
++$cursor;
break;
case '{':
$value .= $this->lexInlineMapping($cursor);
$value .= $this->lexInlineMapping($cursor, false);
break;
case '[':
$value .= $this->lexInlineSequence($cursor);
$value .= $this->lexInlineSequence($cursor, false);
break;
case $closingTag:
$value .= $this->currentLine[$cursor];
++$cursor;

if ($consumeUntilEol && isset($this->currentLine[$cursor]) && (strspn($this->currentLine, ' ', $cursor) + $cursor) < strlen($this->currentLine)) {
throw new ParseException(sprintf('Unexpected token "%s".', trim(substr($this->currentLine, $cursor))));
}

return $value;
case '#':
break 2;
Expand Down
52 changes: 52 additions & 0 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,34 @@ 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 Expand Up @@ -2223,6 +2251,30 @@ public function testRootLevelInlineMappingFollowedByMoreContentIsInvalid()
$this->parser->parse($yaml);
}

public function testInlineMappingFollowedByMoreContentIsInvalid()
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Unexpected token "baz" at line 1 (near "{ foo: bar } baz").');

$yaml = <<<YAML
{ foo: bar } baz
YAML;

$this->parser->parse($yaml);
}

public function testInlineSequenceFollowedByMoreContentIsInvalid()
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Unexpected token ",bar," at line 1 (near "[\'foo\'],bar,").');

$yaml = <<<YAML
['foo'],bar,
YAML;

$this->parser->parse($yaml);
}

public function testTaggedInlineMapping()
{
$this->assertSameData(new TaggedValue('foo', ['foo' => 'bar']), $this->parser->parse('!foo {foo: bar}', Yaml::PARSE_CUSTOM_TAGS));
Expand Down

0 comments on commit ff52a85

Please sign in to comment.