[Yaml][Inline] Fail properly on empty object tag and empty const tag
This commit is contained in:
parent
db3134eba4
commit
bdf02c0a7e
@ -506,7 +506,12 @@ class Inline
|
|||||||
|
|
||||||
if ('!php/const' === $key) {
|
if ('!php/const' === $key) {
|
||||||
$key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true);
|
$key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true);
|
||||||
$key = self::evaluateScalar($key, $flags);
|
if ('!php/const:' === $key && ':' !== $mapping[$i]) {
|
||||||
|
$key = '';
|
||||||
|
--$i;
|
||||||
|
} else {
|
||||||
|
$key = self::evaluateScalar($key, $flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
|
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
|
||||||
@ -692,6 +697,10 @@ class Inline
|
|||||||
return null;
|
return null;
|
||||||
case 0 === strpos($scalar, '!php/object'):
|
case 0 === strpos($scalar, '!php/object'):
|
||||||
if (self::$objectSupport) {
|
if (self::$objectSupport) {
|
||||||
|
if (!isset($scalar[12])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return unserialize(self::parseScalar(substr($scalar, 12)));
|
return unserialize(self::parseScalar(substr($scalar, 12)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -717,6 +726,10 @@ class Inline
|
|||||||
return null;
|
return null;
|
||||||
case 0 === strpos($scalar, '!php/const'):
|
case 0 === strpos($scalar, '!php/const'):
|
||||||
if (self::$constantSupport) {
|
if (self::$constantSupport) {
|
||||||
|
if (!isset($scalar[11])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
|
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
|
||||||
return \constant($const);
|
return \constant($const);
|
||||||
|
@ -799,4 +799,47 @@ class InlineTest extends TestCase
|
|||||||
'negative octal number' => [-28, '-034'],
|
'negative octal number' => [-28, '-034'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider phpObjectTagWithEmptyValueProvider
|
||||||
|
*/
|
||||||
|
public function testPhpObjectWithEmptyValue($expected, $value)
|
||||||
|
{
|
||||||
|
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function phpObjectTagWithEmptyValueProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[false, '!php/object'],
|
||||||
|
[false, '!php/object '],
|
||||||
|
[false, '!php/object '],
|
||||||
|
[[false], '[!php/object]'],
|
||||||
|
[[false], '[!php/object ]'],
|
||||||
|
[[false, 'foo'], '[!php/object , foo]'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider phpConstTagWithEmptyValueProvider
|
||||||
|
*/
|
||||||
|
public function testPhpConstTagWithEmptyValue($expected, $value)
|
||||||
|
{
|
||||||
|
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function phpConstTagWithEmptyValueProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['', '!php/const'],
|
||||||
|
['', '!php/const '],
|
||||||
|
['', '!php/const '],
|
||||||
|
[[''], '[!php/const]'],
|
||||||
|
[[''], '[!php/const ]'],
|
||||||
|
[['', 'foo'], '[!php/const , foo]'],
|
||||||
|
[['' => 'foo'], '{!php/const: foo}'],
|
||||||
|
[['' => 'foo'], '{!php/const : foo}'],
|
||||||
|
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user