Skip to content

Commit

Permalink
feature #19504 [Yaml] deprecate missing space after mapping key colon…
Browse files Browse the repository at this point in the history
… (xabbuh)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Yaml] deprecate missing space after mapping key colon

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #19436, #19472
| License       | MIT
| Doc PR        |

Commits
-------

9a31eef deprecate missing space after mapping key colon
  • Loading branch information
fabpot committed Aug 2, 2016
2 parents a0b22f0 + 9a31eef commit e408b50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar

// key
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
$i = strpos($mapping, ':', $i);

if (!isset($mapping[$i + 1]) || ' ' !== $mapping[$i + 1]) {
@trigger_error('Omitting the space after the colon that follows a mapping key definition is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
}

// value
$done = false;
Expand Down
15 changes: 13 additions & 2 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ public function testParseInvalidMappingKeyShouldThrowException()
Inline::parse($value);
}

/**
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
*/
public function testParseMappingKeyWithColonNotFollowedBySpace()
{
ErrorAssert::assertDeprecationsAreTriggered('Omitting the space after the colon that follows a mapping key definition is deprecated since version 3.2 and will throw a ParseException in 4.0.', function () {
Inline::parse('{1:""}');
});
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
Expand Down Expand Up @@ -376,7 +387,7 @@ public function getTestsForParse()
array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),

// mappings
array('{foo:bar,bar:foo,false:false,null:null,integer:12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
Expand Down Expand Up @@ -443,7 +454,7 @@ public function getTestsForParseWithMapObjects()
array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),

// mappings
array('{foo:bar,bar:foo,false:false,null:null,integer:12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
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')),
Expand Down

0 comments on commit e408b50

Please sign in to comment.