Skip to content

Commit 47e720a

Browse files
committed
[Yaml] fail when parsing mappings without keys
1 parent 68d6415 commit 47e720a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Symfony/Component/Yaml/Inline.php

+4
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array())
384384
// key
385385
$key = self::parseScalar($mapping, array(':', ' '), array('"', "'"), $i, false);
386386

387+
if (':' === $key) {
388+
throw new ParseException('A mapping without a key is invalid.');
389+
}
390+
387391
// value
388392
$done = false;
389393

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

+18
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,22 @@ public function testVeryLongQuotedStrings()
420420

421421
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
422422
}
423+
424+
public function testBooleanMappingKeysAreConvertedToStrings()
425+
{
426+
$this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}'));
427+
}
428+
429+
public function testTheEmptyStringIsAValidMappingKey()
430+
{
431+
$this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }'));
432+
}
433+
434+
/**
435+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
436+
*/
437+
public function testMappingKeysCannotBeOmitted()
438+
{
439+
Inline::parse('{: foo}');
440+
}
423441
}

0 commit comments

Comments
 (0)