minor #23635 [Yaml] Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS (GuilhemN)
This PR was merged into the 3.3 branch.
Discussion
----------
[Yaml] Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | no
| New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks? | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass? | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | https://github.com/symfony/symfony/pull/22948/files#r126940623
<!--
- Bug fixes must be submitted against the lowest branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the 3.4,
legacy code removals go to the master branch.
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->
Commits
-------
9fd425ea14
Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS
This commit is contained in:
commit
a00b05e3ed
@ -365,8 +365,7 @@ Yaml
|
||||
|
||||
* Deprecated support for implicitly parsing non-string mapping keys as strings.
|
||||
Mapping keys that are no strings will lead to a `ParseException` in Symfony
|
||||
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
|
||||
strings.
|
||||
4.0. Use quotes to opt-in for keys to be parsed as strings.
|
||||
|
||||
Before:
|
||||
|
||||
@ -374,7 +373,6 @@ Yaml
|
||||
$yaml = <<<YAML
|
||||
null: null key
|
||||
true: boolean true
|
||||
1: integer key
|
||||
2.0: float key
|
||||
YAML;
|
||||
|
||||
@ -386,13 +384,12 @@ Yaml
|
||||
```php
|
||||
|
||||
$yaml = <<<YAML
|
||||
null: null key
|
||||
true: boolean true
|
||||
1: integer key
|
||||
2.0: float key
|
||||
"null": null key
|
||||
"true": boolean true
|
||||
"2.0": float key
|
||||
YAML;
|
||||
|
||||
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
|
||||
Yaml::parse($yaml);
|
||||
```
|
||||
|
||||
* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.
|
||||
|
@ -326,8 +326,8 @@ FrameworkBundle
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` class
|
||||
has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass`
|
||||
class instead.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
|
||||
Use `Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
|
||||
|
||||
HttpFoundation
|
||||
@ -555,8 +555,8 @@ Yaml
|
||||
throws a `ParseException`.
|
||||
|
||||
* Removed support for implicitly parsing non-string mapping keys as strings.
|
||||
Mapping keys that are no strings will result in a `ParseException`. Use the
|
||||
`PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
|
||||
Mapping keys that are no strings will result in a `ParseException`. Use
|
||||
quotes to opt-in for keys to be parsed as strings.
|
||||
|
||||
Before:
|
||||
|
||||
@ -564,7 +564,6 @@ Yaml
|
||||
$yaml = <<<YAML
|
||||
null: null key
|
||||
true: boolean true
|
||||
1: integer key
|
||||
2.0: float key
|
||||
YAML;
|
||||
|
||||
@ -576,13 +575,12 @@ Yaml
|
||||
```php
|
||||
|
||||
$yaml = <<<YAML
|
||||
null: null key
|
||||
true: boolean true
|
||||
1: integer key
|
||||
2.0: float key
|
||||
"null": null key
|
||||
"true": boolean true
|
||||
"2.0": float key
|
||||
YAML;
|
||||
|
||||
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
|
||||
Yaml::parse($yaml);
|
||||
```
|
||||
|
||||
* Omitting the key of a mapping is not supported anymore and throws a `ParseException`.
|
||||
|
@ -9,8 +9,7 @@ CHANGELOG
|
||||
|
||||
* Deprecated support for implicitly parsing non-string mapping keys as strings.
|
||||
Mapping keys that are no strings will lead to a `ParseException` in Symfony
|
||||
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
|
||||
strings.
|
||||
4.0. Use quotes to opt-in for keys to be parsed as strings.
|
||||
|
||||
Before:
|
||||
|
||||
@ -18,7 +17,6 @@ CHANGELOG
|
||||
$yaml = <<<YAML
|
||||
null: null key
|
||||
true: boolean true
|
||||
1: integer key
|
||||
2.0: float key
|
||||
YAML;
|
||||
|
||||
@ -30,13 +28,12 @@ CHANGELOG
|
||||
```php
|
||||
|
||||
$yaml = <<<YAML
|
||||
null: null key
|
||||
true: boolean true
|
||||
1: integer key
|
||||
2.0: float key
|
||||
"null": null key
|
||||
"true": boolean true
|
||||
"2.0": float key
|
||||
YAML;
|
||||
|
||||
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
|
||||
Yaml::parse($yaml);
|
||||
```
|
||||
|
||||
* Omitted mapping values will be parsed as `null`.
|
||||
|
@ -494,7 +494,7 @@ class Inline
|
||||
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
|
||||
|
||||
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
|
||||
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.', E_USER_DEPRECATED);
|
||||
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ class Parser
|
||||
|
||||
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key) && !is_int($key)) {
|
||||
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
|
||||
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.', $keyType), E_USER_DEPRECATED);
|
||||
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// Convert float keys to strings, to avoid being converted to integers by PHP
|
||||
|
@ -730,7 +730,7 @@ class InlineTest extends TestCase
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
|
||||
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
|
||||
* @dataProvider getNotPhpCompatibleMappingKeyData
|
||||
*/
|
||||
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)
|
||||
|
@ -1081,7 +1081,7 @@ EOF;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
|
||||
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
|
||||
*/
|
||||
public function testFloatKeys()
|
||||
{
|
||||
@ -1103,7 +1103,7 @@ EOF;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRINGS flag to explicitly enable the type casts.
|
||||
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
|
||||
*/
|
||||
public function testBooleanKeys()
|
||||
{
|
||||
|
Reference in New Issue
Block a user