Skip to content

Commit 7233ac2

Browse files
committed
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 symfony/symfony#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
2 parents 86849af + f45861c commit 7233ac2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ private function parseValue($value, $flags, $context)
757757
$lines[] = trim($this->currentLine);
758758

759759
// quoted string values end with a line that is terminated with the quotation character
760-
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
760+
$escapedLine = str_replace(['\\\\', '\\"'], '', $this->currentLine);
761+
if ('' !== $escapedLine && substr($escapedLine, -1) === $quotation) {
761762
break;
762763
}
763764
}

Tests/ParserTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,33 @@ public function testBlankLinesInQuotedMultiLineString()
16501650
$this->assertSame($expected, $this->parser->parse($yaml));
16511651
}
16521652

1653+
public function testEscapedQuoteInQuotedMultiLineString()
1654+
{
1655+
$yaml = <<<YAML
1656+
foobar: "foo
1657+
\\"bar\\"
1658+
baz"
1659+
YAML;
1660+
$expected = [
1661+
'foobar' => 'foo "bar" baz',
1662+
];
1663+
1664+
$this->assertSame($expected, $this->parser->parse($yaml));
1665+
}
1666+
1667+
public function testBackslashInQuotedMultiLineString()
1668+
{
1669+
$yaml = <<<YAML
1670+
foobar: "foo
1671+
bar\\\\"
1672+
YAML;
1673+
$expected = [
1674+
'foobar' => 'foo bar\\',
1675+
];
1676+
1677+
$this->assertSame($expected, $this->parser->parse($yaml));
1678+
}
1679+
16531680
public function testParseMultiLineUnquotedString()
16541681
{
16551682
$yaml = <<<EOT

0 commit comments

Comments
 (0)