8000 [Yaml] Fix escaped quotes in quoted multi-line string · symfony/symfony@2e99caa · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e99caa

Browse files
committed
[Yaml] Fix escaped quotes in quoted multi-line string
1 parent 9e0a39e commit 2e99caa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

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

753753
// quoted string values end with a line that is terminated with the quotation character
754-
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
754+
$escapedLine = str_replace(['\\\\', '\\"'], '', $this->currentLine);
755+
if ('' !== $escapedLine && substr($escapedLine, -1) === $quotation) {
755756
break;
756757
}
757758
}

src/Symfony/Component/Yaml/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)
0