8000 throw meaningful exception for complex mappings · symfony/symfony@4d0be12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d0be12

Browse files
committed
throw meaningful exception for complex mappings
1 parent c12727d commit 4d0be12

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ public function parse($value, $flags = 0)
301301
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine);
302302
}
303303

304+
if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) {
305+
throw new ParseException('The parser does not support complex mappings.', $this->currentLineNb + 1, $this->currentLine);
306+
}
307+
304308
// 1-liner optionally followed by newline(s)
305309
if (is_string($value) && $this->lines[0] === trim($value)) {
306310
try {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,52 @@ public function testExceptionWhenUsingUnsuportedBuiltInTags()
16401640
$this->parser->parse('!!foo');
16411641
}
16421642

1643+
/**
1644+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
1645+
* @expectedExceptionMessageRegExp /^The parser does not support complex mappings/
1646+
*/
1647+
public function testComplexMappingThrowsParseException()
1648+
{
1649+
$yaml = <<<YAML
1650+
? "1"
1651+
:
1652+
name: végétalien
1653+
YAML;
1654+
1655+
$this->parser->parse($yaml);
1656+
}
1657+
1658+
/**
1659+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
1660+
* @expectedExceptionMessageRegExp /^The parser does not support complex mappings/
1661+
*/
1662+
public function testComplexMappingNestedInMappingThrowsParseException()
1663+
{
1664+
$yaml = <<<YAML
1665+
diet:
1666+
? "1"
1667+
:
1668+
name: végétalien
1669+
YAML;
1670+
1671+
$this->parser->parse($yaml);
1672+
}
1673+
1674+
/**
1675+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
1676+
* @expectedExceptionMessageRegExp /^The parser does not support complex mappings/
1677+
*/
1678+
public function testComplexMappingNestedInSequenceThrowsParseException()
1679+
{
1680+
$yaml = <<<YAML
1681+
- ? "1"
1682+
:
1683+
name: végétalien
1684+
YAML;
1685+
1686+
$this->parser->parse($yaml);
1687+
}
1688+
16431689
private function loadTestsFromFixtureFiles($testsFile)
16441690
{
16451691
$parser = new Parser();

0 commit comments

Comments
 (0)
0