Skip to content

Commit

Permalink
[Yaml] throw a ParseException on invalid data type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xabbuh authored and fabpot committed Jul 26, 2015
1 parent 08f696c commit adc6b30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -234,7 +234,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
}

// 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) {
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -551,6 +551,21 @@ public function testMappingInASequence()
);
}

/**
* @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
Expand Down

0 comments on commit adc6b30

Please sign in to comment.