Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7882c4a

Browse files
committed
bug #39274 [Yaml] fix lexing mapping values with trailing whitespaces (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- [Yaml] fix lexing mapping values with trailing whitespaces | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39265 (comment) | License | MIT | Doc PR | Commits ------- 5e455f3 fix lexing mapping values with trailing whitespaces
2 parents 782ee5d + 5e455f3 commit 7882c4a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,10 @@ private function parseValue(string $value, int $flags, string $context)
753753
switch ($value[0] ?? '') {
754754
case '"':
755755
case "'":
756-
$cursor = \strlen($this->currentLine) - \strlen($value);
756+
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
757757
$parsedValue = Inline::parse($this->lexInlineQuotedString($cursor), $flags, $this->refs);
758758

759-
if (isset($this->currentLine[$cursor]) && preg_replace('/\s*#.*$/A', '', substr($this->currentLine, $cursor))) {
759+
if (isset($this->currentLine[$cursor]) && preg_replace('/\s*(#.*)?$/A', '', substr($this->currentLine, $cursor))) {
760760
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($this->currentLine, $cursor)));
761761
}
762762

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2671,7 +2671,7 @@ public function testParseValueWithNegativeModifiers()
26712671
);
26722672
}
26732673

2674-
public function testMultipleWhitespaceAtEndOfLine()
2674+
public function testWhitespaceAtEndOfLine()
26752675
{
26762676
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
26772677
$this->assertSame(
@@ -2692,6 +2692,14 @@ public function testMultipleWhitespaceAtEndOfLine()
26922692
],
26932693
$this->parser->parse($yaml)
26942694
);
2695+
2696+
$this->assertSame(
2697+
[
2698+
'foo' => 'bar',
2699+
'foobar' => 'baz',
2700+
],
2701+
$this->parser->parse("foo: 'bar' \nfoobar: baz")
2702+
);
26952703
}
26962704

26972705
/**

0 commit comments

Comments
 (0)