Skip to content

Commit 4c4b6f4

Browse files
committed
Merge branch '6.4' into 7.2
* 6.4: Review validator-related japanese translations with ids 114-120 don't trigger "internal" deprecations for PHPUnit Stub objects drop comments while lexing unquoted strings
2 parents ac238f1 + 28ee818 commit 4c4b6f4

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

Parser.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,18 @@ 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+
1169+
while ($cursor < strlen($this->currentLine)) {
1170+
if (in_array($this->currentLine[$cursor], ['[', ']', '{', '}', ',', ':'], true)) {
1171+
break;
1172+
}
1173+
1174+
if (\in_array($this->currentLine[$cursor], [' ', "\t"], true) && '#' === ($this->currentLine[$cursor + 1] ?? '')) {
1175+
break;
1176+
}
1177+
1178+
++$cursor;
1179+
}
11691180

11701181
if ($cursor === $offset) {
11711182
throw new ParseException('Malformed unquoted YAML string.');
@@ -1242,7 +1253,7 @@ private function consumeWhitespaces(int &$cursor): bool
12421253
$whitespacesConsumed = 0;
12431254

12441255
do {
1245-
$whitespaceOnlyTokenLength = strspn($this->currentLine, ' ', $cursor);
1256+
$whitespaceOnlyTokenLength = strspn($this->currentLine, " \t", $cursor);
12461257
$whitespacesConsumed += $whitespaceOnlyTokenLength;
12471258
$cursor += $whitespaceOnlyTokenLength;
12481259

Tests/ParserTest.php

+63
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,69 @@ public function testParseMultiLineUnquotedString()
17691769
$this->assertSame(['foo' => 'bar baz foobar foo', 'bar' => 'baz'], $this->parser->parse($yaml));
17701770
}
17711771

1772+
/**
1773+
* @dataProvider unquotedStringWithTrailingComment
1774+
*/
1775+
public function testParseMultiLineUnquotedStringWithTrailingComment(string $yaml, array $expected)
1776+
{
1777+
$this->assertSame($expected, $this->parser->parse($yaml));
1778+
}
1779+
1780+
public function unquotedStringWithTrailingComment()
1781+
{
1782+
return [
1783+
'comment after comma' => [
1784+
<<<'YAML'
1785+
{
1786+
foo: 3, # comment
1787+
bar: 3
1788+
}
1789+
YAML,
1790+
['foo' => 3, 'bar' => 3],
1791+
],
1792+
'comment after space' => [
1793+
<<<'YAML'
1794+
{
1795+
foo: 3 # comment
1796+
}
1797+
YAML,
1798+
['foo' => 3],
1799+
],
1800+
'comment after space, but missing space after #' => [
1801+
<<<'YAML'
1802+
{
1803+
foo: 3 #comment
1804+
}
1805+
YAML,
1806+
['foo' => 3],
1807+
],
1808+
'comment after tab' => [
1809+
<<<YAML
1810+
{
1811+
foo: 3\t# comment
1812+
}
1813+
YAML,
1814+
['foo' => 3],
1815+
],
1816+
'comment after tab, but missing space after #' => [
1817+
<<<YAML
1818+
{
1819+
foo: 3\t#comment
1820+
}
1821+
YAML,
1822+
['foo' => 3],
1823+
],
1824+
'# in mapping value' => [
1825+
<<<'YAML'
1826+
{
1827+
foo: example.com/#about
1828+
}
1829+
YAML,
1830+
['foo' => 'example.com/#about'],
1831+
],
1832+
];
1833+
}
1834+
17721835
/**
17731836
* @dataProvider escapedQuotationCharactersInQuotedStrings
17741837
*/

0 commit comments

Comments
 (0)