8000 consistently parse omitted keys as the colon · symfony/symfony@b1988f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1988f7

Browse files
committed
consistently parse omitted keys as the colon
1 parent 444b37d commit b1988f7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,15 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
477477
// key
478478
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false);
479479

480-
if (false === $i = strpos($mapping, ':', $i)) {
480+
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
481481
break;
482482
}
483483

484-
if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true)) {
484+
if (':' === $key) {
485+
throw new ParseException('A mapping without a key is invalid.');
486+
}
487+
488+
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
485489
@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);
486490
}
487491

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,24 @@ public function testVeryLongQuotedStrings()
686686

687687
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
688688
}
689+
690+
public function testBooleanMappingKeysAreConvertedToStrings()
691+
{
692+
$this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}'));
693+
}
694+
695+
public function testTheEmptyStringIsAValidMappingKey()
696+
{
697+
$this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }'));
698+
}
699+
700+
/**
701+
* @group legacy
702+
* @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.
703+
*/
704+
public function testMappingKeysCannotBeOmitted()
705+
{
706+
Inline::parse('{: foo}');
707+
$this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}'));
708+
}
689709
}

0 commit comments

Comments
 (0)
0