bug #18899 [Yaml] search for colons in strings only (xabbuh)
This PR was merged into the 3.1 branch.
Discussion
----------
[Yaml] search for colons in strings only
| Q | A
| ------------- | ---
| Branch? | 3.1
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #18897
| License | MIT
| Doc PR |
Since the parser is able to return `\DateTime` instances when the
`Yaml::PARSE_DATETIME` flag is passed, we need to ensure that the parsed
value actually is a string before passing the parsed value to string
functions.
Commits
-------
0ea2228
[Yaml] search for colons in strings only
This commit is contained in:
commit
922f1b0e60
|
@ -539,7 +539,7 @@ class Parser
|
|||
try {
|
||||
$parsedValue = Inline::parse($value, $flags, $this->refs);
|
||||
|
||||
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
|
||||
if ('mapping' === $context && is_string($parsedValue) && '"' !== $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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -1230,6 +1230,19 @@ EOT
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseDateAsMappingValue()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
date: 2002-12-14
|
||||
EOT;
|
||||
$expectedDate = new \DateTime();
|
||||
$expectedDate->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$expectedDate->setDate(2002, 12, 14);
|
||||
$expectedDate->setTime(0, 0, 0);
|
||||
|
||||
$this->assertEquals(array('date' => $expectedDate), $this->parser->parse($yaml, Yaml::PARSE_DATETIME));
|
||||
}
|
||||
}
|
||||
|
||||
class B
|
||||
|
|
Reference in New Issue