8000 [Yaml] do not swallow subsequent spaces in unquoted mapping values by xabbuh · Pull Request #59309 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
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
10 changes: 5 additions & 5 deletions src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ private function lexInlineStructure(int &$cursor, string $closingTag): string
$value .= $this->lexUnquotedString($cursor);
}

if ($this->consumeWhitespaces($cursor)) {
$value .= ' ';
if (0 < $numberOfConsumedWhitespaces = $this->consumeWhitespaces($cursor)) {
$value .= isset($this->currentLine[$cursor]) ? str_repeat(' ', $numberOfConsumedWhitespaces) : ' ';
}
}

Expand All @@ -1226,7 +1226,7 @@ private function lexInlineStructure(int &$cursor, string $closingTag): string
throw new ParseException('Malformed inline YAML string.');
}

private function consumeWhitespaces(int &$cursor): bool
private function consumeWhitespaces(int &$cursor): int
{
$whitespacesConsumed = 0;

Expand All @@ -1236,14 +1236,14 @@ private function consumeWhitespaces(int &$cursor): bool
$cursor += $whitespaceOnlyTokenLength;

if (isset($this->currentLine[$cursor])) {
return 0 < $whitespacesConsumed;
return $whitespacesConsumed;
}

if ($this->hasMoreLines()) {
$cursor = 0;
}
} while ($this->moveToNextLine());

return 0 < $whitespacesConsumed;
return $whitespacesConsumed;
}
}
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,11 @@ public static function inlineNotationSpanningMultipleLinesProvider(): array
];
}

public function testParseSubsequentSpacesInsideUnquotedInlineMappingValueNestedInSequence()
{
$this->assertSame([['name' => 'A B']], $this->parser->parse('- {name: A B}'));
}

public function testRootLevelInlineMappingFollowedByMoreContentIsInvalid()
{
$this->expectException(ParseException::class);
Expand Down
0