[Component] [Yaml] [Parser] : can parse with trailing space as 2.8

This commit is contained in:
Jordan Samouh 2017-03-29 12:18:37 +02:00
parent 329b1819f1
commit ce3d5ab7d1
2 changed files with 12 additions and 1 deletions

View File

@ -175,7 +175,7 @@ class Parser
$this->refs[$isRef] = end($data);
}
} elseif (
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', $this->currentLine, $values)
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))
) {
if ($context && 'sequence' == $context) {

View File

@ -602,6 +602,17 @@ YAML;
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
}
public function testCanParseContentWithTrailingSpaces()
{
$yaml = "items: \n foo: bar";
$expected = array(
'items' => array('foo' => 'bar'),
);
$this->assertSame($expected, $this->parser->parse($yaml));
}
/**
* @group legacy
* @dataProvider invalidDumpedObjectProvider