[Yaml] fix parsing multi-line mapping values

This commit is contained in:
Christian Flothmann 2015-12-05 10:54:40 +01:00
parent 84229f84fb
commit 3954530ba7
2 changed files with 49 additions and 0 deletions

View File

@ -571,6 +571,29 @@ class Parser
}
try {
$quotation = '' !== $value && ('"' === $value[0] || "'" === $value[0]) ? $value[0] : null;
// do not take following lines into account when the current line is a quoted single line value
if (null !== $quotation && preg_match('/^'.$quotation.'.*'.$quotation.'(\s*#.*)?$/', $value)) {
return Inline::parse($value, $flags, $this->refs);
}
while ($this->moveToNextLine()) {
// unquoted strings end before the first unindented line
if (null === $quotation && $this->getCurrentLineIndentation() === 0) {
$this->moveToPreviousLine();
break;
}
$value .= ' '.trim($this->currentLine);
// quoted string values end with a line that is terminated with the quotation character
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
break;
}
}
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
$parsedValue = Inline::parse($value, $flags, $this->refs);

View File

@ -1425,6 +1425,32 @@ YAML
),
);
}
public function testParseMultiLineQuotedString()
{
$yaml = <<<EOT
foo: "bar
baz
foobar
foo"
bar: baz
EOT;
$this->assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml));
}
public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT
foo: bar
baz
foobar
foo
bar: baz
EOT;
$this->assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml));
}
}
class B