Skip to content

Commit

Permalink
[Yaml] Throw exception for invalid tagged scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Oct 2, 2019
1 parent 766162c commit 0ab8404
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Expand Up @@ -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');
Expand Down

0 comments on commit 0ab8404

Please sign in to comment.