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
This commit is contained in:
Christophe Coevoet 2015-12-02 09:13:48 +01:00
commit 1552a70e05
2 changed files with 19 additions and 7 deletions

View File

@ -471,12 +471,14 @@ class Parser
return $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
}
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($value, ': ')) {
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
}
try {
return Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
$parsedValue = Inline::parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
}
return $parsedValue;
} catch (ParseException $e) {
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
$e->setSnippet($this->currentLine);

View File

@ -785,8 +785,8 @@ EOF;
}
/**
* @expectedException Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage A colon cannot be used in an unquoted mapping value.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage A colon cannot be used in an unquoted mapping value
*/
public function testColonInMappingValueException()
{
@ -796,6 +796,16 @@ EOF;
$this->parser->parse($yaml);
}
public function testColonInMappingValueExceptionNotTriggeredByColonInComment()
{
$yaml = <<<EOT
foo:
bar: foobar # Note: a comment after a colon
EOT;
$this->assertSame(array('foo' => array('bar' => 'foobar')), $this->parser->parse($yaml));
}
}
class B