Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83052dd

Browse files
committed
drop comments while lexing unquoted strings
1 parent0266d3c commit83052dd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

‎src/Symfony/Component/Yaml/Parser.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,18 @@ private function lexInlineQuotedString(int &$cursor = 0): string
11581158
privatefunctionlexUnquotedString(int &$cursor):string
11591159
{
11601160
$offset =$cursor;
1161-
$cursor +=strcspn($this->currentLine,'[]{},:',$cursor);
1161+
1162+
while ($cursor <strlen($this->currentLine)) {
1163+
if (in_array($this->currentLine[$cursor], ['[',']','{','}',',',':'],true)) {
1164+
break;
1165+
}
1166+
1167+
if ('' ===$this->currentLine[$cursor] &&'#' === ($this->currentLine[$cursor +1] ??'')) {
1168+
break;
1169+
}
1170+
1171+
++$cursor;
1172+
}
11621173

11631174
if ($cursor ===$offset) {
11641175
thrownewParseException('Malformed unquoted YAML string.');

‎src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,19 @@ public function testParseMultiLineUnquotedString()
17511751
$this->assertSame(['foo' =>'bar baz foobar foo','bar' =>'baz'],$this->parser->parse($yaml));
17521752
}
17531753

1754+
publicfunctiontestParseMultiLineUnquotedStringWithTrailingComment()
1755+
{
1756+
$yaml =<<<YAML
1757+
{
1758+
foo: 3, # comment
1759+
bar: example.com/#about,
1760+
baz: 30 # comment
1761+
}
1762+
YAML;
1763+
1764+
$this->assertSame(['foo' =>3,'bar' =>'example.com/#about','baz' =>30],$this->parser->parse($yaml));
1765+
}
1766+
17541767
/**
17551768
* @dataProvider escapedQuotationCharactersInQuotedStrings
17561769
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp