8000 bug #22216 [Component] [Yaml] [Parser] : can parse with trailing spa… · symfony/symfony@19a9b2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 19a9b2f

Browse files
committed
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 ------- ce3d5ab [Component] [Yaml] [Parser] : can parse with trailing space as 2.8
2 parents b570db5 + ce3d5ab commit 19a9b2f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function parse($value, $flags = 0)
175175
$this->refs[$isRef] = end($data);
176176
}
177177
} elseif (
178-
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', $this->currentLine, $values)
178+
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
179179
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))
180180
) {
181181
if ($context && 'sequence' == $context) {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,17 @@ public function testObjectsSupportDisabledWithExceptions($yaml)
602602
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
603603
}
604604

605+
public function testCanParseContentWithTrailingSpaces()
606+
{
607+
$yaml = "items: \n foo: bar";
608+
609+
$expected = array(
610+
'items' => array('foo' => 'bar'),
611+
);
612+
613+
$this->assertSame($expected, $this->parser->parse($yaml));
614+
}
615+
605616
/**
606617
* @group legacy
607618
* @dataProvider invalidDumpedObjectProvider

0 commit comments

Comments
 (0)
0