From 43599362a2c33fa065164d8fe52d8ef5348389dc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 6 Apr 2018 13:01:31 +0200 Subject: [PATCH] [Yaml] Throw parse error on unfinished inline map --- src/Symfony/Component/Yaml/Inline.php | 3 +++ src/Symfony/Component/Yaml/Tests/InlineTest.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 31a0514fd4972..5e5b1a1767ee2 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -231,6 +231,9 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter 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))); } diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index f28f360489f66..418c7876a13c9 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -432,4 +432,13 @@ public function testTheEmptyStringIsAValidMappingKey() { $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'"); + } }