Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -751,7 +751,8 @@ private function parseValue($value, $flags, $context)
$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);
xabbuh marked this conversation as resolved.
Show resolved Hide resolved
if ('' !== $escapedLine && substr($escapedLine, -1) === $quotation) {
break;
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -1650,6 +1650,33 @@ public function testBlankLinesInQuotedMultiLineString()
$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
Expand Down