Skip to content

Commit 9db31f0

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: (27 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 Remove outdated guard from security xsd schema Bump Symfony version to 7.1.11 Update VERSION for 7.1.10 Update CHANGELOG for 7.1.10 Bump Symfony version to 6.4.18 Update VERSION for 6.4.17 ...
2 parents 099581e + ff52a85 commit 9db31f0

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
@@ -1165,7 +1165,7 @@ private function lexInlineQuotedString(int &$cursor = 0): string
11651165
private function lexUnquotedString(int &$cursor): string
11661166
{
11671167
$offset = $cursor;
1168-
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
1168+
$cursor += strcspn($this->currentLine, '[]{},:', $cursor);
11691169

11701170
if ($cursor === $offset) {
11711171
throw new ParseException('Malformed unquoted YAML string.');
@@ -1174,17 +1174,17 @@ private function lexUnquotedString(int &$cursor): string
11741174
return substr($this->currentLine, $offset, $cursor - $offset);
11751175
}
11761176

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

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

1187-
private function lexInlineStructure(int &$cursor, string $closingTag): string
1187+
private function lexInlineStructure(int &$cursor, string $closingTag, bool $consumeUntilEol = true): string
11881188
{
11891189
$value = $this->currentLine[$cursor];
11901190
++$cursor;
@@ -1204,15 +1204,19 @@ private function lexInlineStructure(int &$cursor, string $closingTag): string
12041204
++$cursor;
12051205
break;
12061206
case '{':
1207-
$value .= $this->lexInlineMapping($cursor);
1207+
$value .= $this->lexInlineMapping($cursor, false);
12081208
break;
12091209
case '[':
1210-
$value .= $this->lexInlineSequence($cursor);
1210+
$value .= $this->lexInlineSequence($cursor, false);
12111211
break;
12121212
case $closingTag:
12131213
$value .= $this->currentLine[$cursor];
12141214
++$cursor;
12151215

1216+
if ($consumeUntilEol && isset($this->currentLine[$cursor]) && (strspn($this->currentLine, ' ', $cursor) + $cursor) < strlen($this->currentLine)) {
1217+
throw new ParseException(sprintf('Unexpected token "%s".', trim(substr($this->currentLine, $cursor))));
1218+
}
1219+
12161220
return $value;
12171221
case '#':
12181222
break 2;

Tests/ParserTest.php

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

1731+
/**
1732+
* @dataProvider wrappedUnquotedStringsProvider
1733+
*/
1734+
public function testWrappedUnquotedStringWithMultipleSpacesInValue(string $yaml, array $expected)
1735+
{
1736+
$this->assertSame($expected, $this->parser->parse($yaml));
1737+
}
1738+
1739+
public static function wrappedUnquotedStringsProvider()
1740+
{
1741+
return [
1742+
'mapping' => [
1743+
'{ foo: bar bar, fiz: cat cat }',
1744+
[
1745+
'foo' => 'bar bar',
1746+
'fiz' => 'cat cat',
1747+
]
1748+
],
1749+
'sequence' => [
1750+
'[ bar bar, cat cat ]',
1751+
[
1752+
'bar bar',
1753+
'cat cat',
1754+
]
1755+
],
1756+
];
1757+
}
1758+
17311759
public function testParseMultiLineUnquotedString()
17321760
{
17331761
$yaml = <<<EOT
@@ -2243,6 +2271,30 @@ public function testRootLevelInlineMappingFollowedByMoreContentIsInvalid()
22432271
$this->parser->parse($yaml);
22442272
}
22452273

2274+
public function testInlineMappingFollowedByMoreContentIsInvalid()
2275+
{
2276+
$this->expectException(ParseException::class);
2277+
$this->expectExceptionMessage('Unexpected token "baz" at line 1 (near "{ foo: bar } baz").');
2278+
2279+
$yaml = <<<YAML
2280+
{ foo: bar } baz
2281+
YAML;
2282+
2283+
$this->parser->parse($yaml);
2284+
}
2285+
2286+
public function testInlineSequenceFollowedByMoreContentIsInvalid()
2287+
{
2288+
$this->expectException(ParseException::class);
2289+
$this->expectExceptionMessage('Unexpected token ",bar," at line 1 (near "[\'foo\'],bar,").');
2290+
2291+
$yaml = <<<YAML
2292+
['foo'],bar,
2293+
YAML;
2294+
2295+
$this->parser->parse($yaml);
2296+
}
2297+
22462298
public function testTaggedInlineMapping()
22472299
{
22482300
$this->assertSameData(new TaggedValue('foo', ['foo' => 'bar']), $this->parser->parse('!foo {foo: bar}', Yaml::PARSE_CUSTOM_TAGS));

0 commit comments

Comments
 (0)