Skip to content

Commit dfe3462

Browse files
committed
consistently parse omitted keys as the colon
1 parent 9724c68 commit dfe3462

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Inline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
459459
// key
460460
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
461461

462-
if (false === $i = strpos($mapping, ':', $i)) {
462+
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
463463
break;
464464
}
465465

466-
if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true)) {
466+
if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
467467
@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);
468468
}
469469

Tests/InlineTest.php

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

687687
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
688688
}
689+
690+
public function testOmittedMappingKeyIsParsedAsColon()
691+
{
692+
$this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}'));
693+
}
689694
}

0 commit comments

Comments
 (0)