bug #22216 [Component] [Yaml] [Parser] : can parse with trailing space as 2.8 (jordscream)

This PR was merged into the 3.3-dev branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #22193
| License       | MIT
| Doc PR        | symfony/symfony-docs

Missing rtrim method in line to parse as the version 2.8 does

Commits
-------

ce3d5ab7d1 [Component] [Yaml] [Parser] :  can parse with trailing space as 2.8
This commit is contained in:
Fabien Potencier 2017-03-31 16:30:03 +02:00
commit 19a9b2f29b
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