diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index b9b399937be67..1fbfeed7ba7dc 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 74dc8ff19a5c9..dec786b83a979 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(ParseException::class); + $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');