8000 [Yaml] Deprecate using the object and const tag without a value · symfony/symfony@73d8d4e · GitHub
[go: up one dir, main page]

Skip to content

Commit 73d8d4e

Browse files
committed
[Yaml] Deprecate using the object and const tag without a value
1 parent af4035d commit 73d8d4e

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

UPGRADE-5.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ Routing
2323
-------
2424

2525
* Deprecated `RouteCollectionBuilder` in favor of `RoutingConfigurator`.
26+
27+
Yaml
28+
----
29+
30+
* Deprecated using the `!php/object` and `!php/const` tags without a value.

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* Added `yaml-lint` binary.
8+
* Deprecated using the `!php/object` and `!php/const` tags without a value.
89

910
5.0.0
1011
-----

src/Symfony/Component/Yaml/Inline.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
435435
$isKeyQuoted = \in_array($mapping[$i], ['"', "'"], true);
436436
$key = self::parseScalar($mapping, $flags, [':', ' '], $i, false, []);
437437

438+
if ('!php/const' === $key) {
439+
$key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, []);
440+
$key = self::evaluateScalar($key, $flags);
441+
}
442+
438443
if ($offsetBeforeKeyParsing === $i) {
439444
throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping);
440445
}
@@ -584,6 +589,12 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
584589
return substr($scalar, 2);
585590
case 0 === strpos($scalar, '!php/object'):
586591
if (self::$objectSupport) {
592+
if (!isset($scalar[12])) {
593+
@trigger_error('Using the !php/object tag without a value is deprecated since Symfony 5.1.', E_USER_DEPRECATED);
594+
595+
return false;
596+
}
597+
587598
return unserialize(self::parseScalar(substr($scalar, 12)));
588599
}
589600

@@ -594,6 +605,12 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
594605
return null;
595606
case 0 === strpos($scalar, '!php/const'):
596607
if (self::$constantSupport) {
608+
if (!isset($scalar[11])) {
609+
@trigger_error('Using the !php/const tag without a value is deprecated since Symfony 5.1.', E_USER_DEPRECATED);
610+
611+
return '';
612+
}
613+
597614
$i = 0;
598615
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
599616
return \constant($const);

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,55 @@ public function getTestsForOctalNumbers()
736736
'negative octal number' => [-28, '-034'],
737737
];
738738
}
739+
740+
/**
741+
* @dataProvider phpObjectTagWithEmptyValueProvider
742+
*
743+
* @group legacy
744+
*
745+
* @expectedDeprecation Using the !php/object tag without a value is deprecated since Symfony 5.1.
746+
*/
747+
public function testPhpObjectWithEmptyValue($expected, $value)
748+
{
749+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
750+
}
751+
752+
public function phpObjectTagWithEmptyValueProvider()
753+
{
754+
return [
755+
[false, '!php/object'],
756+
[false, '!php/object '],
757+
[false, '!php/object '],
758+
[[false], '[!php/object]'],
759+
[[false], '[!php/object ]'],
760+
[[false, 'foo'], '[!php/object , foo]'],
761+
];
762+
}
763+
764+
/**
765+
* @dataProvider phpConstTagWithEmptyValueProvider
766+
*
767+
* @group legacy
768+
*
769+
* @expectedDeprecation Using the !php/const tag without a value is deprecated since Symfony 5.1.
770+
*/
771+
public function testPhpConstTagWithEmptyValue($expected, $value)
772+
{
773+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
774+
}
775+
776+
public function phpConstTagWithEmptyValueProvider()
777+
{
778+
return [
779+
['', '!php/const'],
780+
['', '!php/const '],
781+
['', '!php/const '],
782+
[[''], '[!php/const]'],
783+
[[''], '[!php/const ]'],
784+
[['', 'foo'], '[!php/const , foo]'],
785+
[['' => 'foo'], '{!php/const: foo}'],
786+
[['' => 'foo'], '{!php/const : foo}'],
787+
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
788+
];
789+
}
739790
}

0 commit comments

Comments
 (0)
0