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:
commit
19a9b2f29b
@ -175,7 +175,7 @@ class Parser
|
|||||||
$this->refs[$isRef] = end($data);
|
$this->refs[$isRef] = end($data);
|
||||||
}
|
}
|
||||||
} elseif (
|
} 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('"', "'")))
|
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))
|
||||||
) {
|
) {
|
||||||
if ($context && 'sequence' == $context) {
|
if ($context && 'sequence' == $context) {
|
||||||
|
@ -602,6 +602,17 @@ YAML;
|
|||||||
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
|
$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
|
* @group legacy
|
||||||
* @dataProvider invalidDumpedObjectProvider
|
* @dataProvider invalidDumpedObjectProvider
|
||||||
|
Reference in New Issue
Block a user