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 5396cbc

Browse filesBrowse files
committed
[Yaml][Inline] Fail properly on empty object tag and empty const tag
1 parent db3134e commit 5396cbc
Copy full SHA for 5396cbc

File tree

2 files changed

+37
-2
lines changed
Filter options

2 files changed

+37
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,11 @@ private static function evaluateScalar($scalar, $flags, $references = [])
692692
return null;
693693
case 0 === strpos($scalar, '!php/object'):
694694
if (self::$objectSupport) {
695-
return unserialize(self::parseScalar(substr($scalar, 12)));
695+
if ((false === $str = substr($scalar, 12)) || '' === $str) {
696+
throw new ParseException('The !php/object tag requires a value.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
697+
}
698+
699+
return unserialize(self::parseScalar($str));
696700
}
697701

698702
if (self::$exceptionOnInvalidType) {
@@ -717,8 +721,12 @@ private static function evaluateScalar($scalar, $flags, $references = [])
717721
return null;
718722
case 0 === strpos($scalar, '!php/const'):
719723
if (self::$constantSupport) {
724+
if ((false === $const = substr($scalar, 11)) || '' === $const) {
725+
throw new ParseException('The !php/const tag requires a value.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
726+
}
727+
720728
$i = 0;
721-
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
729+
if (\defined($const = self::parseScalar($const, 0, null, $i, false))) {
722730
return \constant($const);
723731
}
724732

‎src/Symfony/Component/Yaml/Tests/InlineTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,4 +799,31 @@ public function getTestsForOctalNumbers()
799799
'negative octal number' => [-28, '-034'],
800800
];
801801
}
802+
803+
/**
804+
* @dataProvider tagThrowsOnEmptyProvider
805+
*/
806+
public function testTagThrowsOnEmpty($tag, $inMapping, $flags)
807+
{
808+
$this->expectException(ParseException::class);
809+
$this->expectExceptionMessage(sprintf('The %s tag requires a value at line 1 (near "%s").', $tag, $tag));
810+
811+
if ($inMapping) {
812+
$value = sprintf('{%s : bar}', $tag);
813+
} else {
814+
$value = $tag.' ';
815+
}
816+
817+
Inline::parse($value, $flags);
818+
}
819+
820+
public function tagThrowsOnEmptyProvider()
821+
{
822+
return [
823+
['!php/object', false, Yaml::PARSE_OBJECT],
824+
['!php/object', true, Yaml::PARSE_OBJECT],
825+
['!php/const', false, Yaml::PARSE_CONSTANT],
826+
['!php/const', true, Yaml::PARSE_CONSTANT],
827+
];
828+
}
802829
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.