diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 56322c387d386..20365a6583b8e 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -1170,7 +1170,9 @@ private function lexInlineQuotedString(int &$cursor = 0): string for (; \strlen($this->currentLine) > $cursor; ++$cursor) { switch ($this->currentLine[$cursor]) { case '\\': - if (isset($this->currentLine[++$cursor])) { + if ("'" === $quotation) { + $value .= '\\'; + } elseif (isset($this->currentLine[++$cursor])) { $value .= '\\'.$this->currentLine[$cursor]; } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index cea3d3f330a71..bc5332e5135b2 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1618,6 +1618,11 @@ public function escapedQuotationCharactersInQuotedStrings() ]; } + public function testBackslashInSingleQuotedString() + { + $this->assertSame(['foo' => 'bar\\'], $this->parser->parse("foo: 'bar\'")); + } + public function testParseMultiLineString() { $this->assertEquals("foo bar\nbaz", $this->parser->parse("foo\nbar\n\nbaz"));