8000 [Yaml] Throw exception for invalid tagged scalar · symfony/symfony@0ab8404 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ab8404

Browse files
committed
[Yaml] Throw exception for invalid tagged scalar
1 parent 766162c commit 0ab8404

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 4 additions & 4 deletions
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

Lines changed: 7 additions & 0 deletions
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('Symfony\Component\Yaml\Exception\ParseException');
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)
0