bug #36743 [Yaml] Fix escaped quotes in quoted multi-line string (ossinkine)

This PR was merged into the 3.4 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

This PR continues https://github.com/symfony/symfony/pull/19304

This PR fixes incorrect parsing quoted multi-line string which contain escaped quotes, see tests

Commits
-------

2e99caacaf [Yaml] Fix escaped quotes in quoted multi-line string
This commit is contained in:
Fabien Potencier 2020-05-11 09:51:54 +02:00
commit a8cb3cd2da
2 changed files with 29 additions and 1 deletions

View File

@ -757,7 +757,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