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

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
[Yaml] Fixed infinite loop when parser goes through an additional and…
… invalid closing tag

Instead of letting the parser goes in an infinite loop, throw an exception when the additional and invalid is found
  • Loading branch information
alexandre-daubois committed Apr 5, 2021
commit d5f8c887a2e7d65312dc4136e2f1343a88883f6b
4 changes: 4 additions & 0 deletions src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,10 @@ private function lexUnquotedString(int &$cursor): string
$offset = $cursor;
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);

if ($cursor === $offset) {
throw new ParseException('Malformed unquoted YAML string.');
}

return substr($this->currentLine, $offset, $cursor - $offset);
}

Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,25 @@ public function testParseValueWithNegativeModifiers()
);
}

public function testThrowExceptionIfInvalidAdditionalClosingTagOccurs()
{
$yaml = '{
"object": {
"array": [
"a",
"b",
"c"
]
],
}
}';

$this->expectException(ParseException::class);
$this->expectExceptionMessage('Malformed unquoted YAML string at line 8 (near " ],").');

$this->parser->parse($yaml);
}

public function testWhitespaceAtEndOfLine()
{
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
Expand Down