[Yaml] Throw exception for tagged invalid inline elements

This commit is contained in:
Gregor Harlan 2019-10-16 00:08:58 +02:00
parent e7f70415a5
commit bed479c561
No known key found for this signature in database
GPG Key ID: A43C725D9D2AE675
2 changed files with 10 additions and 4 deletions

View File

@ -126,15 +126,15 @@ class Inline
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
}
if (null !== $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) {
return new TaggedValue($tag, $result);
}
return $result;
} finally {
if (isset($mbEncoding)) {

View File

@ -201,6 +201,12 @@ class InlineTest extends TestCase
Inline::parse('{ foo: bar } bar');
}
public function testParseInvalidTaggedSequenceShouldThrowException()
{
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');
Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS);
}
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
{
$value = "'don''t do somthin'' like that'";