8000 deprecate missing space after mapping key colon · c960657/symfony@9a31eef · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a31eef

Browse files
committed
deprecate missing space after mapping key colon
1 parent 983b560 commit 9a31eef

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
456456

457457
// key
458458
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
459+
$i = strpos($mapping, ':', $i);
460+
461+
if (!isset($mapping[$i + 1]) || ' ' !== $mapping[$i + 1]) {
462+
@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);
463+
}
459464

460465
// value
461466
$done = false;

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ public function testParseInvalidMappingKeyShouldThrowException()
165165
Inline::parse($value);
166166
}
167167

168+
/**
169+
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
170+
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
171+
*/
172+
public function testParseMappingKeyWithColonNotFollowedBySpace()
173+
{
174+
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 () {
175+
Inline::parse('{1:""}');
176+
});
177+
}
178+
168179
/**
169180
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
170181
*/
@@ -376,7 +387,7 @@ public function getTestsForParse()
376387
array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
377388

378389
// mappings
379-
array('{foo:bar,bar:foo,false:false,null:null,integer:12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
390+
array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
380391
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
381392
array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
382393
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
@@ -443,7 +454,7 @@ public function getTestsForParseWithMapObjects()
443454
array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
444455

445456
// mappings
446-
array('{foo:bar,bar:foo,false:false,null:null,integer:12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
457+
array('{foo: bar,bar: foo,false: false,null: null,integer: 12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
447458
array('{ foo : bar, bar : foo, false : false, null : null, integer : 12 }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
448459
array('{foo: \'bar\', bar: \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
449460
array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),

0 commit comments

Comments
 (0)
0