Skip to content

Commit 6f349c6

Browse files
committed
bug #16745 [Yaml] look for colon in parsed inline string (xabbuh)
This PR was merged into the 2.8 branch. Discussion ---------- [Yaml] look for colon in parsed inline string | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16562 | License | MIT | Doc PR | Looking for a colon in an unquoted mapping value can lead to falsely reported parse errors (e.g. when a comment after the mapping value contains a colon). Commits ------- 2127058 [Yaml] look for colon in parsed inline string
2 parents 6ff5015 + 2127058 commit 6f349c6

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,17 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport, $ob
473473
return $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
474474
}
475475

476-
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($value, ': ')) {
477-
@trigger_error(sprintf('Using a colon in an unquoted mapping value in line %d is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $this->getRealCurrentLineNb() + 1), E_USER_DEPRECATED);
476+
try {
477+
$parsedValue = Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
478478

479-
// to be thrown in 3.0
480-
// throw new ParseException('A colon cannot be used in an unquoted mapping value.');
481-
}
479+
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
480+
@trigger_error(sprintf('Using a colon in an unquoted mapping value in line %d is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $this->getRealCurrentLineNb() + 1), E_USER_DEPRECATED);
482481

483-
try {
484-
return Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
482+
// to be thrown in 3.0
483+
// throw new ParseException('A colon cannot be used in an unquoted mapping value.');
484+
}
485+
486+
return $parsedValue;
485487
} catch (ParseException $e) {
486488
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
487489
$e->setSnippet($this->currentLine);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,16 @@ public function testColonInMappingValueException()
808808

809809
restore_error_handler();
810810
}
811+
812+
public function testColonInMappingValueExceptionNotTriggeredByColonInComment()
813+
{
814+
$yaml = <<<EOT
815+
foo:
816+
bar: foobar # Note: a comment after a colon
817+
EOT;
818+
819+
$this->assertSame(array('foo' => array('bar' => 'foobar')), $this->parser->parse($yaml));
820+
}
811821
}
812822

813823
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