Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Yaml] Throw exception for tagged invalid inline elements #33818

Merged
merged 1 commit into from Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Symfony/Component/Yaml/Inline.php
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 src/Symfony/Component/Yaml/Tests/InlineTest.php
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