Skip to content

Commit 3c5d915

Browse files
committed
deprecate implicit string casting of mapping keys
1 parent e7c12d3 commit 3c5d915

28 files changed

+367
-109
lines changed

UPGRADE-3.3.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,37 @@ Workflow
246246
Yaml
247247
----
248248

249+
* Deprecated support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
250+
lead to a `ParseException` in Symfony 4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
251+
strings.
252+
253+
Before:
254+
255+
```php
256+
$yaml = <<<YAML
257+
null: null key
258+
true: boolean true
259+
1: integer key
260+
2.0: float key
261+
YAML;
262+
263+
Yaml::parse($yaml);
264+
```
265+
266+
After:
267+
268+
```php
269+
270+
$yaml = <<<YAML
271+
null: null key
272+
true: boolean true
273+
1: integer key
274+
2.0: float key
275+
YAML;
276+
277+
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
278+
```
279+
249280
* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.
250281

251282
* The constructor arguments `$offset`, `$totalNumberOfLines` and

UPGRADE-4.0.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,36 @@ Workflow
463463
Yaml
464464
----
465465

466+
* Removed support for implicitly parsing non-string mapping keys as strings. Mapping keys that are no strings will
467+
result in a `ParseException`. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
468+
469+
Before:
470+
471+
```php
472+
$yaml = <<<YAML
473+
null: null key
474+
true: boolean true
475+
1: integer key
476+
2.0: float key
477+
YAML;
478+
479+
Yaml::parse($yaml);
480+
```
481+
482+
After:
483+
484+
```php
485+
486+
$yaml = <<<YAML
487+
null: null key
488+
true: boolean true
489+
1: integer key
490+
2.0: float key
491+
YAML;
492+
493+
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
494+
```
495+
466496
* Omitting the key of a mapping is not supported anymore and throws a `ParseException`.
467497

468498
* Mappings with a colon (`:`) that is not followed by a whitespace are not

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ protected function loadFile($file)
602602
}
603603

604604
try {
605-
$configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
605+
$configuration = $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_KEYS_AS_STRINGS);
606606
} catch (ParseException $e) {
607607
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
608608
}

src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Yaml\Exception\ParseException;
1818
use Symfony\Component\Yaml\Parser as YamlParser;
1919
use Symfony\Component\Config\Loader\FileLoader;
20+
use Symfony\Component\Yaml\Yaml;
2021

2122
/**
2223
* YamlFileLoader loads Yaml routing files.
@@ -58,7 +59,7 @@ public function load($file, $type = null)
5859
}
5960

6061
try {
61-
$parsedConfig = $this->yamlParser->parse(file_get_contents($path));
62+
$parsedConfig = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRINGS);
6263
} catch (ParseException $e) {
6364
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
6465
}

src/Symfony/Component/Routing/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
"require-dev": {
2222
"symfony/config": "~2.8|~3.0",
2323
"symfony/http-foundation": "~2.8|~3.0",
24-
"symfony/yaml": "~2.8|~3.0",
24+
"symfony/yaml": "~3.3",
2525
"symfony/expression-language": "~2.8|~3.0",
2626
"symfony/dependency-injection": "~2.8|~3.0",
2727
"doctrine/annotations": "~1.0",
2828
"doctrine/common": "~2.2",
2929
"psr/log": "~1.0"
3030
},
3131
"conflict": {
32-
"symfony/config": "<2.8"
32+
"symfony/config": "<2.8",
33+
"symfony/yaml": "<3.3"
3334
},
3435
"suggest": {
3536
"symfony/http-foundation": "For using a Symfony Request object",

src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
1616
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
1717
use Symfony\Component\Yaml\Parser;
18+
use Symfony\Component\Yaml\Yaml;
1819

1920
/**
2021
* YAML File Loader.
@@ -113,7 +114,7 @@ private function getClassesFromYaml()
113114
$this->yamlParser = new Parser();
114115
}
115116

116-
$classes = $this->yamlParser->parse(file_get_contents($this->file));
117+
$classes = $this->yamlParser->parse(file_get_contents($this->file), Yaml::PARSE_KEYS_AS_STRINGS);
117118

118119
if (empty($classes)) {
119120
return array();

src/Symfony/Component/Serializer/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9"
2020
},
2121
"require-dev": {
22-
"symfony/yaml": "~3.1",
22+
"symfony/yaml": "~3.3",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/property-access": "~2.8|~3.0",
2525
"symfony/http-foundation": "~2.8|~3.0",
@@ -34,7 +34,7 @@
3434
"symfony/dependency-injection": "<3.2",
3535
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4",
3636
"symfony/property-info": "<3.1",
37-
"symfony/yaml": "<3.1"
37+
"symfony/yaml": "<3.3"
3838
},
3939
"suggest": {
4040
"psr/cache-implementation": "For using the metadata cache.",

src/Symfony/Component/Translation/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Translation\Exception\LogicException;
1616
use Symfony\Component\Yaml\Parser as YamlParser;
1717
use Symfony\Component\Yaml\Exception\ParseException;
18+
use Symfony\Component\Yaml\Yaml;
1819

1920
/**
2021
* YamlFileLoader loads translations from Yaml files.
@@ -39,7 +40,7 @@ protected function loadResource($resource)
3940
}
4041

4142
try {
42-
$messages = $this->yamlParser->parse(file_get_contents($resource));
43+
$messages = $this->yamlParser->parse(file_get_contents($resource), Yaml::PARSE_KEYS_AS_STRINGS);
4344
} catch (ParseException $e) {
4445
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
4546
}

src/Symfony/Component/Translation/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
"require-dev": {
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/intl": "^2.8.18|^3.2.5",
25-
"symfony/yaml": "~2.8|~3.0",
25+
"symfony/yaml": "~3.3",
2626
"psr/log": "~1.0"
2727
},
2828
"conflict": {
29-
"symfony/config": "<2.8"
29+
"symfony/config": "<2.8",
30+
"symfony/yaml": "<3.3"
3031
},
3132
"suggest": {
3233
"symfony/config": "",

src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Validator\Mapping\ClassMetadata;
1515
use Symfony\Component\Yaml\Exception\ParseException;
1616
use Symfony\Component\Yaml\Parser as YamlParser;
17+
use Symfony\Component\Yaml\Yaml;
1718

1819
/**
1920
* Loads validation metadata from a YAML file.
@@ -115,7 +116,7 @@ protected function parseNodes(array $nodes)
115116
private function parseFile($path)
116117
{
117118
try {
118-
$classes = $this->yamlParser->parse(file_get_contents($path));
119+
$classes = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRINGS);
119120
} catch (ParseException $e) {
120121
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
121122
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy