Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ private function parseValue(string $value, int $flags, string $context)

try {
if ('' !== $value && '{' === $value[0]) {
$cursor = \strlen($this->currentLine) - \strlen($value);
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));

return Inline::parse($this->lexInlineMapping($cursor), $flags, $this->refs);
} elseif ('' !== $value && '[' === $value[0]) {
$cursor = \strlen($this->currentLine) - \strlen($value);
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));

return Inline::parse($this->lexInlineSequence($cursor), $flags, $this->refs);
}
Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,29 @@ public function testParseValueWithNegativeModifiers()
);
}

public function testMultipleWhitespaceAtEndOfLine()
{
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
$this->assertSame(
[
'foo' => [
'arguments' => ['@bar'],
],
],
$this->parser->parse($yaml)
);

$yaml = "\nfoo:\n bar: {} \n";
$this->assertSame(
[
'foo' => [
'bar' => [],
],
],
$this->parser->parse($yaml)
);
}

/**
* This is a regression test for a bug where a YAML block with a nested multiline string using | was parsed without
* a trailing \n when a shorter YAML document was parsed before.
Expand Down