Skip to content

Commit

Permalink
[Yaml] Throw exception for tagged invalid inline elements
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Oct 15, 2019
1 parent 768f817 commit 471ca8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ public static function parse($value, $flags = 0, $references = [])
$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)) {
Expand Down
6 changes: 6 additions & 0 deletions Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public function testParseInvalidSequenceShouldThrowException()
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'";
Expand Down

0 comments on commit 471ca8e

Please sign in to comment.