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:
commit
a8cb3cd2da
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user