bug #22829 [Yaml] fix colon without space deprecation (xabbuh)
This PR was merged into the 3.2 branch.
Discussion
----------
[Yaml] fix colon without space deprecation
| Q | A
| ------------- | ---
| Branch? | 3.2
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
A colon after a mapping key that is not followed by a space is valid if the mapping key is quoted.
Commits
-------
57f6941e25
[Yaml] fix colon without space deprecation
This commit is contained in:
commit
ec4689122c
@ -5,8 +5,8 @@ CHANGELOG
|
||||
-----
|
||||
|
||||
* Mappings with a colon (`:`) that is not followed by a whitespace are deprecated
|
||||
and will lead to a `ParseException` in Symfony 4.0 (e.g. `foo:bar` must be
|
||||
`foo: bar`).
|
||||
when the mapping key is not quoted and will lead to a `ParseException` in
|
||||
Symfony 4.0 (e.g. `foo:bar` must be `foo: bar`).
|
||||
|
||||
* Added support for parsing PHP constants:
|
||||
|
||||
|
@ -461,14 +461,15 @@ class Inline
|
||||
}
|
||||
|
||||
// key
|
||||
$isKeyQuoted = in_array($mapping[$i], array('"', "'"), true);
|
||||
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
|
||||
|
||||
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
|
||||
@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);
|
||||
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
|
||||
@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);
|
||||
}
|
||||
|
||||
// value
|
||||
|
@ -168,7 +168,7 @@ class InlineTest extends TestCase
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @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.
|
||||
* @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.
|
||||
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||
*/
|
||||
public function testParseMappingKeyWithColonNotFollowedBySpace()
|
||||
@ -391,6 +391,8 @@ class InlineTest extends TestCase
|
||||
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
|
||||
array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
|
||||
array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
|
||||
array('{"foo:bar": "baz"}', array('foo:bar' => 'baz')),
|
||||
array('{"foo":"bar"}', array('foo' => 'bar')),
|
||||
|
||||
// nested sequences and mappings
|
||||
array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
|
||||
@ -460,6 +462,8 @@ class InlineTest extends TestCase
|
||||
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
|
||||
array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (object) array('foo\'' => 'bar', 'bar"' => 'foo: bar')),
|
||||
array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', (object) array('foo: ' => 'bar', 'bar: ' => 'foo: bar')),
|
||||
array('{"foo:bar": "baz"}', (object) array('foo:bar' => 'baz')),
|
||||
array('{"foo":"bar"}', (object) array('foo' => 'bar')),
|
||||
|
||||
// nested sequences and mappings
|
||||
array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
|
||||
|
Reference in New Issue
Block a user