bug #15361 [Yaml] throw a ParseException on invalid data type (xabbuh)
This PR was submitted for the 2.8 branch but it was merged into the 2.6 branch instead (closes #15361).
Discussion
----------
[Yaml] throw a ParseException on invalid data type
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #15234
| License | MIT
| Doc PR |
Without this check, PHP would trigger a warning when an array was passed
to `trim()`. The parser must throw a `ParseException` instance on a
malformed YAML string instead.
Commits
-------
adc6b30
[Yaml] throw a ParseException on invalid data type
This commit is contained in:
commit
e338281601
@ -234,7 +234,7 @@ class Parser
|
||||
}
|
||||
|
||||
// 1-liner optionally followed by newline(s)
|
||||
if ($this->lines[0] === trim($value)) {
|
||||
if (is_string($value) && $this->lines[0] === trim($value)) {
|
||||
try {
|
||||
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
|
||||
} catch (ParseException $e) {
|
||||
|
@ -551,6 +551,21 @@ EOF
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
* @expectedExceptionMessage missing colon
|
||||
*/
|
||||
public function testScalarInSequence()
|
||||
{
|
||||
Yaml::parse(<<<EOF
|
||||
foo:
|
||||
- bar
|
||||
"missing colon"
|
||||
foo: bar
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* > It is an error for two equal keys to appear in the same mapping node.
|
||||
* > In such a case the YAML processor may continue, ignoring the second
|
||||
|
Reference in New Issue
Block a user