[Yaml Parser] fixed Parser to skip comments when inlining sequences

This commit is contained in:
Andre Eckardt 2020-09-02 22:39:27 +02:00 committed by Fabien Potencier
parent 6c2a1c9a57
commit b5316ebebb
2 changed files with 31 additions and 1 deletions

View File

@ -1244,7 +1244,13 @@ class Parser
for ($i = 1; isset($this->currentLine[$i]) && ']' !== $this->currentLine[$i]; ++$i) {
}
$value .= trim($this->currentLine);
$trimmedValue = trim($this->currentLine);
if ('' !== $trimmedValue && '#' === $trimmedValue[0]) {
continue;
}
$value .= $trimmedValue;
if (isset($this->currentLine[$i]) && ']' === $this->currentLine[$i]) {
break;

View File

@ -1898,6 +1898,30 @@ YAML
[new TaggedValue('foo', 'bar')],
'[ !foo bar ]',
],
'with-comments' => [
[
[new TaggedValue('foo', ['foo', 'baz'])],
],
<<<YAML
- [!foo [
foo,
baz
#bar
]]
YAML
],
'with-comments-trailing-comma' => [
[
[new TaggedValue('foo', ['foo', 'baz'])],
],
<<<YAML
- [!foo [
foo,
baz,
#bar
]]
YAML
],
];
}