[Yaml] fix parsing multi-line mapping values
This commit is contained in:
parent
84229f84fb
commit
3954530ba7
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user