Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ea510f

Browse filesBrowse files
committed
bug #21647 [Yaml] consistently parse omitted keys as the colon (xabbuh)
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
2 parents fb8abdc + e2ebecc commit 6ea510f
Copy full SHA for 6ea510f

File tree

2 files changed

+7
-2
lines changed
Filter options

2 files changed

+7
-2
lines changed

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+2-2Lines 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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.