Skip to content

Commit ff52a85

Browse files
committed
Merge branch '6.4' into 7.1
* 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 ...
2 parents 3ced3f2 + fb4722f commit ff52a85

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

Parser.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ private function lexInlineQuotedString(int &$cursor = 0): string
11531153
private function lexUnquotedString(int &$cursor): string
11541154
{
11551155
$offset = $cursor;
1156-
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
1156+
$cursor += strcspn($this->currentLine, '[]{},:', $cursor);
11571157

11581158
if ($cursor === $offset) {
11591159
throw new ParseException('Malformed unquoted YAML string.');
@@ -1162,17 +1162,17 @@ private function lexUnquotedString(int &$cursor): string
11621162
return substr($this->currentLine, $offset, $cursor - $offset);
11631163
}
11641164

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

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

1175-
private function lexInlineStructure(int &$cursor, string $closingTag): string
1175+
private function lexInlineStructure(int &$cursor, string $closingTag, bool $consumeUntilEol = true): string
11761176
{
11771177
$value = $this->currentLine[$cursor];
11781178
++$cursor;
@@ -1192,15 +1192,19 @@ private function lexInlineStructure(int &$cursor, string $closingTag): string
11921192
++$cursor;
11931193
break;
11941194
case '{':
1195-
$value .= $this->lexInlineMapping($cursor);
1195+
$value .= $this->lexInlineMapping($cursor, false);
11961196
break;
11971197
case '[':
1198-
$value .= $this->lexInlineSequence($cursor);
1198+
$value .= $this->lexInlineSequence($cursor, false);
11991199
break;
12001200
case $closingTag:
12011201
$value .= $this->currentLine[$cursor];
12021202
++$cursor;
12031203

1204+
if ($consumeUntilEol && isset($this->currentLine[$cursor]) && (strspn($this->currentLine, ' ', $cursor) + $cursor) < strlen($this->currentLine)) {
1205+
throw new ParseException(sprintf('Unexpected token "%s".', trim(substr($this->currentLine, $cursor))));
1206+
}
1207+
12041208
return $value;
12051209
case '#':
12061210
break 2;

Tests/ParserTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,34 @@ public function testBackslashInQuotedMultiLineString()
17081708
$this->assertSame($expected, $this->parser->parse($yaml));
17091709
}
17101710

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

2254+
public function testInlineMappingFollowedByMoreContentIsInvalid()
2255+
{
2256+
$this->expectException(ParseException::class);
2257+
$this->expectExceptionMessage('Unexpected token "baz" at line 1 (near "{ foo: bar } baz").');
2258+
2259+
$yaml = <<<YAML
2260+
{ foo: bar } baz
2261+
YAML;
2262+
2263+
$this->parser->parse($yaml);
2264+
}
2265+
2266+
public function testInlineSequenceFollowedByMoreContentIsInvalid()
2267+
{
2268+
$this->expectException(ParseException::class);
2269+
$this->expectExceptionMessage('Unexpected token ",bar," at line 1 (near "[\'foo\'],bar,").');
2270+
2271+
$yaml = <<<YAML
2272+
['foo'],bar,
2273+
YAML;
2274+
2275+
$this->parser->parse($yaml);
2276+
}
2277+
22262278
public function testTaggedInlineMapping()
22272279
{
22282280
$this->assertSameData(new TaggedValue('foo', ['foo' => 'bar']), $this->parser->parse('!foo {foo: bar}', Yaml::PARSE_CUSTOM_TAGS));

0 commit comments

Comments
 (0)