Skip to content

Commit

Permalink
bug #21647 [Yaml] consistently parse omitted keys as the colon (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.2 branch.

Discussion
----------

[Yaml] consistently parse omitted keys as the colon

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Before the changes made in #20335, an empty mapping key was parsed as `:`. This behaviour is not correct according to the spec, but we should keep the parser behaviour consistent to not break backward compatibility (I will deprecate it in a different PR on `master`).

Commits
-------

e2ebecc consistently parse omitted keys as the colon
  • Loading branch information
stof committed Feb 17, 2017
2 parents fb8abdc + e2ebecc commit 6ea510f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -459,11 +459,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
// key
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);

if (false === $i = strpos($mapping, ':', $i)) {
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
break;
}

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

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Expand Up @@ -686,4 +686,9 @@ public function testVeryLongQuotedStrings()

$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
}

public function testOmittedMappingKeyIsParsedAsColon()
{
$this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}'));
}
}

0 comments on commit 6ea510f

Please sign in to comment.