[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
This commit is contained in:
parent
3b1948fe72
commit
d5f8c887a2
@ -1225,6 +1225,10 @@ class Parser
|
|||||||
$offset = $cursor;
|
$offset = $cursor;
|
||||||
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
|
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
|
||||||
|
|
||||||
|
if ($cursor === $offset) {
|
||||||
|
throw new ParseException('Malformed unquoted YAML string.');
|
||||||
|
}
|
||||||
|
|
||||||
return substr($this->currentLine, $offset, $cursor - $offset);
|
return substr($this->currentLine, $offset, $cursor - $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2676,6 +2676,25 @@ YAML;
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
public function testWhitespaceAtEndOfLine()
|
||||||
{
|
{
|
||||||
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
|
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
|
||||||
|
Reference in New Issue
Block a user