Skip to content

Commit d9393d8

Browse files
committed
Reapply the Yaml bugfix of symfony#16745
1 parent 7b8865b commit d9393d8

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy