Skip to content

Commit

Permalink
bug #36743 [Yaml] Fix escaped quotes in quoted multi-line string (oss…
Browse files Browse the repository at this point in the history
…inkine)

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 #19304

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

Commits
-------

2e99caa [Yaml] Fix escaped quotes in quoted multi-line string
  • Loading branch information
fabpot committed May 11, 2020
2 parents 1e1060f + 2e99caa commit a8cb3cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -757,7 +757,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);
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

0 comments on commit a8cb3cd

Please sign in to comment.