[Yaml] Fix escaped quotes in quoted multi-line string

This commit is contained in:
Gocha Ossinkine 2020-05-07 22:31:15 +05:00
parent 9e0a39ee05
commit 2e99caacaf
2 changed files with 29 additions and 1 deletions

View File

@ -751,7 +751,8 @@ class Parser
$lines[] = 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) {
$escapedLine = str_replace(['\\\\', '\\"'], '', $this->currentLine);
if ('' !== $escapedLine && substr($escapedLine, -1) === $quotation) {
break;
}
}

View File

@ -1650,6 +1650,33 @@ YAML;
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testEscapedQuoteInQuotedMultiLineString()
{
$yaml = <<<YAML
foobar: "foo
\\"bar\\"
baz"
YAML;
$expected = [
'foobar' => 'foo "bar" baz',
];
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testBackslashInQuotedMultiLineString()
{
$yaml = <<<YAML
foobar: "foo
bar\\\\"
YAML;
$expected = [
'foobar' => 'foo bar\\',
];
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT