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

Skip to content
Sign in

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 780b68c

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

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,53 @@ 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+
public function phpObjectTagWithEmptyValueProvider()
752+
{
753+
return [
754+
[false, '!php/object'],
755+
[false, '!php/object '],
756+
[false, '!php/object '],
757+
[[false], '[!php/object]'],
758+
[[false], '[!php/object ]'],
759+
[[false, 'foo'], '[!php/object , foo]'],
760+
];
761+
}
762+
763+
/**
764+
* @dataProvider phpConstTagWithEmptyValueProvider
765+
*
766+
* @group legacy
767+
*
768+
* @expectedDeprecation Using the !php/const tag without a value is deprecated since Symfony 5.1.
769+
*/
770+
public function testPhpConstTagWithEmptyValue($expected, $value)
771+
{
772+
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
773+
}
774+
public function phpConstTagWithEmptyValueProvider()
775+
{
776+
return [
777+
['', '!php/const'],
778+
['', '!php/const '],
779+
['', '!php/const '],
780+
[[''], '[!php/const]'],
781+
[[''], '[!php/const ]'],
782+
[['', 'foo'], '[!php/const , foo]'],
783+
[['' => 'foo'], '{!php/const: foo}'],
784+
[['' => 'foo'], '{!php/const : foo}'],
785+
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
786+
];
787+
}
739788
}

0 commit comments

Comments
 (0)
0