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 57f6941

Browse filesBrowse files
committed
[Yaml] fix colon without space deprecation
A colon after a mapping key that is not followed by a space is valid if the mapping key is quoted.
1 parent 838518f commit 57f6941
Copy full SHA for 57f6941

File tree

3 files changed

+10
-5
lines changed
Filter options

3 files changed

+10
-5
lines changed

‎src/Symfony/Component/Yaml/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/CHANGELOG.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ CHANGELOG
55
-----
66

77
* Mappings with a colon (`:`) that is not followed by a whitespace are deprecated
8-
and will lead to a `ParseException` in Symfony 4.0 (e.g. `foo:bar` must be
9-
`foo: bar`).
8+
when the mapping key is not quoted and will lead to a `ParseException` in
9+
Symfony 4.0 (e.g. `foo:bar` must be `foo: bar`).
1010

1111
* Added support for parsing PHP constants:
1212

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,15 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
461461
}
462462

463463
// key
464+
$isKeyQuoted = in_array($mapping[$i], array('"', "'"), true);
464465
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
465466

466467
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
467468
break;
468469
}
469470

470-
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
471-
@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);
471+
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
472+
@trigger_error('Using a colon after an unquoted mapping key 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);
472473
}
473474

474475
// value

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testParseInvalidMappingKeyShouldThrowException()
168168

169169
/**
170170
* @group legacy
171-
* @expectedDeprecation 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.
171+
* @expectedDeprecation Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since version 3.2 and will throw a ParseException in 4.0.
172172
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
173173
*/
174174
public function testParseMappingKeyWithColonNotFollowedBySpace()
@@ -391,6 +391,8 @@ public function getTestsForParse()
391391
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
392392
array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
393393
array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
394+
array('{"foo:bar": "baz"}', array('foo:bar' => 'baz')),
395+
array('{"foo":"bar"}', array('foo' => 'bar')),
394396

395397
// nested sequences and mappings
396398
array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
@@ -460,6 +462,8 @@ public function getTestsForParseWithMapObjects()
460462
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
461463
array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (object) array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
462464
array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', (object) array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
465+
array('{"foo:bar": "baz"}', (object) array('foo:bar' => 'baz')),
466+
array('{"foo":"bar"}', (object) array('foo' => 'bar')),
463467

464468
// nested sequences and mappings
465469
array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),

0 commit comments

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