Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1552a70

Browse files
committed
bug #16788 Reapply the Yaml bugfix of #16745 (stof)
This PR was merged into the 3.0 branch. Discussion ---------- Reapply the Yaml bugfix of #16745 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16784 | License | MIT | Doc PR | n/a The fix done in #16745 was missed when resolving conflicts during the merge to 3.0 Commits ------- d9393d8 Reapply the Yaml bugfix of #16745
2 parents 7b8865b + d9393d8 commit 1552a70

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,14 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $ob
471471
return $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
472472
}
473473

474-
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($value, ': ')) {
475-
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
476-
}
477-
478474
try {
479-
return Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
475+
$parsedValue = Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
476+
477+
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
478+
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
479+
}
480+
481+
return $parsedValue;
480482
} catch (ParseException $e) {
481483
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
482484
$e->setSnippet($this->currentLine);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ public function testFloatKeys()
785785
}
786786

787787
/**
788-
* @expectedException Symfony\Component\Yaml\Exception\ParseException
789-
* @expectedExceptionMessage A colon cannot be used in an unquoted mapping value.
788+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
789+
* @expectedExceptionMessage A colon cannot be used in an unquoted mapping value
790790
*/
791791
public function testColonInMappingValueException()
792792
{
@@ -796,6 +796,16 @@ public function testColonInMappingValueException()
796796

797797
$this->parser->parse($yaml);
798798
}
799+
800+
public function testColonInMappingValueExceptionNotTriggeredByColonInComment()
801+
{
802+
$yaml = <<<EOT
803+
foo:
804+
bar: foobar # Note: a comment after a colon
805+
EOT;
806+
807+
$this->assertSame(array('foo' => array('bar' => 'foobar')), $this->parser->parse($yaml));
808+
}
799809
}
800810

801811
class B

0 commit comments

Comments
 (0)