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 f758eca

Browse filesBrowse files
bug #35332 [Yaml][Inline] Fail properly on empty object tag and empty const tag (fancyweb)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml][Inline] Fail properly on empty object tag and empty const tag | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Rework of #35208 to not end up in `parseScalar` with an empty string or a boolean (and thus, avoid unfriendly error such as `Trying to access array offset on value of type bool`). Ping @xabbuh Commits ------- bdf02c0 [Yaml][Inline] Fail properly on empty object tag and empty const tag
2 parents 1f053f9 + bdf02c0 commit f758eca
Copy full SHA for f758eca

File tree

2 files changed

+57
-1
lines changed
Filter options

2 files changed

+57
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,12 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = []
506506

507507
if ('!php/const' === $key) {
508508
$key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true);
509-
$key = self::evaluateScalar($key, $flags);
509+
if ('!php/const:' === $key && ':' !== $mapping[$i]) {
510+
$key = '';
511+
--$i;
512+
} else {
513+
$key = self::evaluateScalar($key, $flags);
514+
}
510515
}
511516

512517
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
@@ -692,6 +697,10 @@ private static function evaluateScalar($scalar, $flags, $references = [])
692697
return null;
693698
case 0 === strpos($scalar, '!php/object'):
694699
if (self::$objectSupport) {
700+
if (!isset($scalar[12])) {
701+
return false;
702+
}
703+
695704
return unserialize(self::parseScalar(substr($scalar, 12)));
696705
}
697706

@@ -717,6 +726,10 @@ private static function evaluateScalar($scalar, $flags, $references = [])
717726
return null;
718727
case 0 === strpos($scalar, '!php/const'):
719728
if (self::$constantSupport) {
729+
if (!isset($scalar[11])) {
730+
return '';
731+
}
732+
720733
$i = 0;
721734
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
722735
return \constant($const);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,4 +799,47 @@ public function getTestsForOctalNumbers()
799799
'negative octal number' => [-28, '-034'],
800800
];
801801
}
802+
803+
/**
804+
* @dataProvider phpObjectTagWithEmptyValueProvider
805+
*/
806+
public function testPhpObjectWithEmptyValue($expected, $value)
807+
{
808+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
809+
}
810+
811+
public function phpObjectTagWithEmptyValueProvider()
812+
{
813+
return [
814+
[false, '!php/object'],
815+
[false, '!php/object '],
816+
[false, '!php/object '],
817+
[[false], '[!php/object]'],
818+
[[false], '[!php/object ]'],
819+
[[false, 'foo'], '[!php/object , foo]'],
820+
];
821+
}
822+
823+
/**
824+
* @dataProvider phpConstTagWithEmptyValueProvider
825+
*/
826+
public function testPhpConstTagWithEmptyValue($expected, $value)
827+
{
828+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
829+
}
830+
831+
public function phpConstTagWithEmptyValueProvider()
832+
{
833+
return [
834+
['', '!php/const'],
835+
['', '!php/const '],
836+
['', '!php/const '],
837+
[[''], '[!php/const]'],
838+
[[''], '[!php/const ]'],
839+
[['', 'foo'], '[!php/const , foo]'],
840+
[['' => 'foo'], '{!php/const: foo}'],
841+
[['' => 'foo'], '{!php/const : foo}'],
842+
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
843+
];
844+
}
802845
}

0 commit comments

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