Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ab8404

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

File tree

Expand file treeCollapse file tree

2 files changed

+11
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-4
lines changed

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+4-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+7Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.