Skip to content

Commit 94d005c

Browse files
Merge branch '3.4' into 4.4
* 3.4: [Phpunit] Fix running skipped tests expecting only deprecations [DependencyInjection] #35505 Fix typo in test name [Yaml][Inline] Fail properly on empty object tag and empty const tag Check non-null type for numeric type Check value isset to avoid PHP notice bug symfony#28179 [DomCrawler] Skip disabled fields processing in Form
2 parents cd014e4 + bc63e15 commit 94d005c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Inline.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
589589
return substr($scalar, 2);
590590
case 0 === strpos($scalar, '!php/object'):
591591
if (self::$objectSupport) {
592+
if (!isset($scalar[12])) {
593+
return false;
594+
}
595+
592596
return unserialize(self::parseScalar(substr($scalar, 12)));
593597
}
594598

@@ -599,6 +603,10 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
599603
return null;
600604
case 0 === strpos($scalar, '!php/const'):
601605
if (self::$constantSupport) {
606+
if (!isset($scalar[11])) {
607+
return '';
608+
}
609+
602610
$i = 0;
603611
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
604612
return \constant($const);

Tests/InlineTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,49 @@ public function getTestsForOctalNumbers()
738738
];
739739
}
740740

741+
/**
742+
* @dataProvider phpObjectTagWithEmptyValueProvider
743+
*/
744+
public function testPhpObjectWithEmptyValue($expected, $value)
745+
{
746+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
747+
}
748+
749+
public function phpObjectTagWithEmptyValueProvider()
750+
{
751+
return [
752+
[false, '!php/object'],
753+
[false, '!php/object '],
754+
[false, '!php/object '],
755+
[[false], '[!php/object]'],
756+
[[false], '[!php/object ]'],
757+
[[false, 'foo'], '[!php/object , foo]'],
758+
];
759+
}
760+
761+
/**
762+
* @dataProvider phpConstTagWithEmptyValueProvider
763+
*/
764+
public function testPhpConstTagWithEmptyValue($expected, $value)
765+
{
766+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
767+
}
768+
769+
public function phpConstTagWithEmptyValueProvider()
770+
{
771+
return [
772+
['', '!php/const'],
773+
['', '!php/const '],
774+
['', '!php/const '],
775+
[[''], '[!php/const]'],
776+
[[''], '[!php/const ]'],
777+
[['', 'foo'], '[!php/const , foo]'],
778+
[['' => 'foo'], '{!php/const: foo}'],
779+
[['' => 'foo'], '{!php/const : foo}'],
780+
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
781+
];
782+
}
783+
741784
/**
742785
* @dataProvider unquotedExclamationMarkThrowsProvider
743786
*/

0 commit comments

Comments
 (0)