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

[Yaml] do not swallow subsequent spaces in unquoted mapping values #59309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of s 8000 ervice and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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