Skip to content

Commit a1b9968

Browse files
committed
[Yaml] Throw exception for invalid tagged scalar
1 parent 6b3bbe4 commit a1b9968

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Symfony/Component/Yaml/Inline.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public static function parse(string $value = null, int $flags = 0, array $refere
9494
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
9595
}
9696

97-
if (null !== $tag && '' !== $tag) {
98-
return new TaggedValue($tag, $result);
99-
}
100-
10197
// some comments are allowed at the end
10298
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
10399
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
104100
}
105101

102+
if (null !== $tag && '' !== $tag) {
103+
return new TaggedValue($tag, $result);
104+
}
105+
106106
return $result;
107107
} finally {
108108
if (isset($mbEncoding)) {

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

+7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowExcep
141141
Inline::parse($value);
142142
}
143143

144+
public function testParseScalarWithTagAndIncorrectlyQuotedStringShouldThrowException()
145+
{
146+
$this->expectException(ParseException::class);
147+
$value = "!foo 'don't do somthin' like that'";
148+
Inline::parse($value, Yaml::PARSE_CUSTOM_TAGS);
149+
}
150+
144151
public function testParseInvalidMappingKeyShouldThrowException()
145152
{
146153
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');

0 commit comments

Comments
 (0)