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

Commit 0206282

Browse filesBrowse files
committed
deprecate implicit string casting of mapping keys
1 parent e7c12d3 commit 0206282
Copy full SHA for 0206282

25 files changed

+275
-109
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+1-1Lines 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_STRING);
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/YamlFileLoader.php
+2-1Lines 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_STRING);
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/composer.json
+3-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php
+2-1Lines 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_STRING);
117118

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

‎src/Symfony/Component/Serializer/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/composer.json
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Loader/YamlFileLoader.php
+2-1Lines 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_STRING);
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/composer.json
+3-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php
+2-1Lines 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_STRING);
119120
} catch (ParseException $e) {
120121
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
121122
}

‎src/Symfony/Component/Validator/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/composer.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require-dev": {
2424
"symfony/http-foundation": "~2.8|~3.0",
2525
"symfony/intl": "^2.8.18|^3.2.5",
26-
"symfony/yaml": "~2.8|~3.0",
26+
"symfony/yaml": "~3.3",
2727
"symfony/config": "~2.8|~3.0",
2828
"symfony/expression-language": "~2.8|~3.0",
2929
"symfony/cache": "~3.1",
@@ -32,7 +32,8 @@
3232
"egulias/email-validator": "^1.2.8|~2.0"
3333
},
3434
"conflict": {
35-
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
35+
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
36+
"symfony/yaml": "<3.3"
3637
},
3738
"suggest": {
3839
"psr/cache-implementation": "For using the metadata cache.",

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,14 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
485485
@trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
486486
}
487487

488+
if (!(Yaml::PARSE_KEYS_AS_STRING & $flags)) {
489+
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
490+
491+
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey)) {
492+
@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_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED);
493+
}
494+
}
495+
488496
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
489497
@trigger_error('Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
490498
}

‎src/Symfony/Component/Yaml/Parser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Parser.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,19 @@ public function parse($value, $flags = 0)
180180
Inline::parse(null, $flags, $this->refs);
181181
try {
182182
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
183-
$key = Inline::parseScalar($values['key']);
183+
$i = 0;
184+
$key = Inline::parseScalar($values['key'], 0, null, $i, !(Yaml::PARSE_KEYS_AS_STRING & $flags));
184185
} catch (ParseException $e) {
185186
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
186187
$e->setSnippet($this->currentLine);
187188

188189
throw $e;
189190
}
190191

192+
if (!(Yaml::PARSE_KEYS_AS_STRING & $flags) && !is_string($key)) {
193+
@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_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED);
194+
}
195+
191196
// Convert float keys to strings, to avoid being converted to integers by PHP
192197
if (is_float($key)) {
193198
$key = (string) $key;

‎src/Symfony/Component/Yaml/Tests/DumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testSpecifications()
125125
// TODO
126126
} else {
127127
eval('$expected = '.trim($test['php']).';');
128-
$this->assertSame($expected, $this->parser->parse($this->dumper->dump($expected, 10)), $test['test']);
128+
$this->assertSame($expected, $this->parser->parse($this->dumper->dump($expected, 10), Yaml::PARSE_KEYS_AS_STRING), $test['test']);
129129
}
130130
}
131131
}

‎src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml
-27Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -556,21 +556,6 @@ php: |
556556
'fixed' => 1230.15,
557557
)
558558
---
559-
test: Miscellaneous
560-
spec: 2.21
561-
yaml: |
562-
null: ~
563-
true: true
564-
false: false
565-
string: '12345'
566-
php: |
567-
array(
568-
'' => null,
569-
1 => true,
570-
0 => false,
571-
'string' => '12345'
572-
)
573-
---
574559
test: Timestamps
575560
todo: true
576561
spec: 2.22
@@ -1533,18 +1518,6 @@ ruby: |
15331518
}
15341519
15351520
---
1536-
test: Boolean
1537-
yaml: |
1538-
false: used as key
1539-
logical: true
1540-
answer: false
1541-
php: |
1542-
array(
1543-
false => 'used as key',
1544-
'logical' => true,
1545-
'answer' => false
1546-
)
1547-
---
15481521
test: Integer
15491522
yaml: |
15501523
canonical: 12345

‎src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml
-14Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,6 @@ php: |
210210
'negative one-thousand' => -1000.0
211211
)
212212
---
213-
test: Integers as Map Keys
214-
brief: >
215-
An integer can be used a dictionary key.
216-
yaml: |
217-
1: one
218-
2: two
219-
3: three
220-
php: |
221-
array(
222-
1 => 'one',
223-
2 => 'two',
224-
3 => 'three'
225-
)
226-
---
227213
test: Floats
228214
dump_skip: true
229215
brief: >
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- %YAML:1.0
2+
test: Miscellaneous
3+
spec: 2.21
4+
yaml: |
5+
true: true
6+
false: false
7+
php: |
8+
array(
9+
'true' => true,
10+
'false' => false,
11+
)
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--- %YAML:1.0
2+
test: Miscellaneous
3+
spec: 2.21
4+
yaml: |
5+
true: true
6+
false: false
7+
php: |
8+
array(
9+
1 => true,
10+
0 => false,
11+
)
12+
---
13+
test: Boolean
14+
yaml: |
15+
false: used as key
16+
logical: true
17+
answer: false
18+
php: |
19+
array(
20+
false => 'used as key',
21+
'logical' => true,
22+
'answer' => false
23+
)
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- legacyBooleanMappingKeys
2+
- legacyNullMappingKey
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- %YAML:1.0
2+
test: Miscellaneous
3+
spec: 2.21
4+
yaml: |
5+
null: ~
6+
php: |
7+
array(
8+
'' => null,
9+
)
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- booleanMappingKeys
2+
- numericMappingKeys
3+
- nullMappingKey
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- %YAML:1.0
2+
test: Miscellaneous
3+
spec: 2.21
4+
yaml: |
5+
null: ~
6+
php: |
7+
array(
8+
'null' => null,
9+
)
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--- %YAML:1.0
2+
test: A sequence with an unordered array
3+
brief: >
4+
A sequence with an unordered array
5+
yaml: |
6+
1: foo
7+
0: bar
8+
php: |
9+
array(1 => 'foo', 0 => 'bar')
10+
---
11+
test: Integers as Map Keys
12+
brief: >
13+
An integer can be used as dictionary key.
14+
yaml: |
15+
1: one
16+
2: two
17+
3: three
18+
php: |
19+
array(
20+
1 => 'one',
21+
2 => 'two',
22+
3 => 'three'
23+
)

‎src/Symfony/Component/Yaml/Tests/Fixtures/sfTests.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/Fixtures/sfTests.yml
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ yaml: |
9696
php: |
9797
array('foo', array('bar' => array('bar' => 'foo')))
9898
---
99-
test: A sequence with an unordered array
100-
brief: >
101-
A sequence with an unordered array
102-
yaml: |
103-
1: foo
104-
0: bar
105-
php: |
106-
array(1 => 'foo', 0 => 'bar')
107-
---
10899
test: Octal
109100
brief: as in spec example 2.19, octal value is converted
110101
yaml: |

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.