Skip to content

Commit 17f70c9

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: (47 commits) Remove comment about AppVeyor in `phpunit` [Webhook][RemoteEvent] fix SendgridPayloadConverter category support Update old Appveyor skip conditions sync the Dutch translation file with changes from the 7.2 branch [Yaml] fix inline notation with inline comment clean up code for doctrine/persistence 2.x Generate missing translations using Gemini fix(property-info): make sure that SerializerExtractor returns null for invalid class metadata add translations for the Slug constraint [RemoteEvent][Webhook] fix SendgridRequestParser & SendgridPayloadConverter in case of missing sg_message_id [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 Fix predis command error checking [Security] Fix triggering session tracking from ContextListener ...
2 parents b5176af + ac238f1 commit 17f70c9

File tree

2 files changed

+77
-8
lines changed

2 files changed

+77
-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]) && ($whitespaces = strspn($this->currentLine, ' ', $cursor) + $cursor) < strlen($this->currentLine) && '#' !== $this->currentLine[$whitespaces]) {
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,34 @@ public function testBackslashInQuotedMultiLineString()
17551755
$this->assertSame($expected, $this->parser->parse($yaml));
17561756
}
17571757

1758+
/**
1759+
* @dataProvider wrappedUnquotedStringsProvider
1760+
*/
1761+
public function testWrappedUnquotedStringWithMultipleSpacesInValue(string $yaml, array $expected)
1762+
{
1763+
$this->assertSame($expected, $this->parser->parse($yaml));
1764+
}
1765+
1766+
public static function wrappedUnquotedStringsProvider()
1767+
{
1768+
return [
1769+
'mapping' => [
1770+
'{ foo: bar bar, fiz: cat cat }',
1771+
[
1772+
'foo' => 'bar bar',
1773+
'fiz' => 'cat cat',
1774+
]
1775+
],
1776+
'sequence' => [
1777+
'[ bar bar, cat cat ]',
1778+
[
1779+
'bar bar',
1780+
'cat cat',
1781+
]
1782+
],
1783+
];
1784+
}
1785+
17581786
public function testParseMultiLineUnquotedString()
17591787
{
17601788
$yaml = <<<EOT
@@ -2178,6 +2206,19 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array
21782206
map: {key: "value", a: "b"}
21792207
param: "some"
21802208
YAML,
2209+
],
2210+
'mixed mapping with inline notation on one line with a comment' => [
2211+
[
2212+
'map' => [
2213+
'key' => 'value',
2214+
'a' => 'b',
2215+
],
2216+
'param' => 'some',
2217+
],
2218+
<<<YAML
2219+
map: {key: "value", a: "b"} # comment
2220+
param: "some"
2221+
YAML
21812222
],
21822223
'mixed mapping with compact inline notation on one line' => [
21832224
[
@@ -2270,6 +2311,30 @@ public function testRootLevelInlineMappingFollowedByMoreContentIsInvalid()
22702311
$this->parser->parse($yaml);
22712312
}
22722313

2314+
public function testInlineMappingFollowedByMoreContentIsInvalid()
2315+
{
2316+
$this->expectException(ParseException::class);
2317+
$this->expectExceptionMessage('Unexpected token "baz" at line 1 (near "{ foo: bar } baz").');
2318+
2319+
$yaml = <<<YAML
2320+
{ foo: bar } baz
2321+
YAML;
2322+
2323+
$this->parser->parse($yaml);
2324+
}
2325+
2326+
public function testInlineSequenceFollowedByMoreContentIsInvalid()
2327+
{
2328+
$this->expectException(ParseException::class);
2329+
$this->expectExceptionMessage('Unexpected token ",bar," at line 1 (near "[\'foo\'],bar,").');
2330+
2331+
$yaml = <<<YAML
2332+
['foo'],bar,
2333+
YAML;
2334+
2335+
$this->parser->parse($yaml);
2336+
}
2337+
22732338
public function testTaggedInlineMapping()
22742339
{
22752340
$this->assertSameData(new TaggedValue('foo', ['foo' => 'bar']), $this->parser->parse('!foo {foo: bar}', Yaml::PARSE_CUSTOM_TAGS));

0 commit comments

Comments
 (0)