From 0ab84044ed3ca97a7257ee7e38fdf3963b085880 Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Wed, 2 Oct 2019 19:37:31 +0200 Subject: [PATCH] [Yaml] Throw exception for invalid tagged scalar --- src/Symfony/Component/Yaml/Inline.php | 8 ++++---- src/Symfony/Component/Yaml/Tests/InlineTest.php | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index b9b399937be6..1fbfeed7ba7d 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -94,15 +94,15 @@ public static function parse(string $value = null, int $flags = 0, array $refere $result = self::parseScalar($value, $flags, null, $i, null === $tag, $references); } - if (null !== $tag && '' !== $tag) { - return new TaggedValue($tag, $result); - } - // some comments are allowed at the end if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename); } + if (null !== $tag && '' !== $tag) { + return new TaggedValue($tag, $result); + } + return $result; } finally { if (isset($mbEncoding)) { diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 74dc8ff19a5c..28494efe4610 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -141,6 +141,13 @@ public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowExcep Inline::parse($value); } + public function testParseScalarWithTagAndIncorrectlyQuotedStringShouldThrowException() + { + $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); + $value = "!foo 'don't do somthin' like that'"; + Inline::parse($value, Yaml::PARSE_CUSTOM_TAGS); + } + public function testParseInvalidMappingKeyShouldThrowException() { $this->expectException('Symfony\Component\Yaml\Exception\ParseException');