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

[Yaml] Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS #23635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions 13 UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,14 @@ 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:

```php
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
YAML;

Expand All @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions 18 UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -555,16 +555,15 @@ 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:

```php
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
YAML;

Expand All @@ -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`.
Expand Down
13 changes: 5 additions & 8 deletions 13 src/Symfony/Component/Yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ 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:

```php
$yaml = <<<YAML
null: null key
true: boolean true
1: integer key
2.0: float key
YAML;

Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
$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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function doParse($value, $flags)

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
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ public function testTheEmptyStringIsAValidMappingKey()

/**
* @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)
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ public function testYamlDirective()

/**
* @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()
{
Expand All @@ -1103,7 +1103,7 @@ public function testFloatKeys()

/**
* @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()
{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.