bug #26834 [Yaml] Throw parse error on unfinished inline map (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Yaml] Throw parse error on unfinished inline map

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Throws a parse error instead of a PHP notice.

Commits
-------

4359936 [Yaml] Throw parse error on unfinished inline map
This commit is contained in:
Christian Flothmann 2018-04-08 09:51:31 +02:00
commit 16edba5d99
2 changed files with 12 additions and 0 deletions

View File

@ -231,6 +231,9 @@ class Inline
if (null !== $delimiters) {
$tmp = ltrim(substr($scalar, $i), ' ');
if ('' === $tmp) {
throw new ParseException(sprintf('Unexpected end of line, expected one of "%s".', implode($delimiters)));
}
if (!in_array($tmp[0], $delimiters)) {
throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i)));
}

View File

@ -432,4 +432,13 @@ class InlineTest extends TestCase
{
$this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }'));
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Unexpected end of line, expected one of ",}".
*/
public function testUnfinishedInlineMap()
{
Inline::parse("{abc: 'def'");
}
}