Skip to content

Commit ae13f07

Browse files
committed
fix lexing backslashes in single quoted strings
1 parent 9919460 commit ae13f07

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Parser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,9 @@ private function lexInlineQuotedString(int &$cursor = 0): string
11701170
for (; \strlen($this->currentLine) > $cursor; ++$cursor) {
11711171
switch ($this->currentLine[$cursor]) {
11721172
case '\\':
1173-
if (isset($this->currentLine[++$cursor])) {
1173+
if ("'" === $quotation) {
1174+
$value .= '\\';
1175+
} elseif (isset($this->currentLine[++$cursor])) {
11741176
$value .= '\\'.$this->currentLine[$cursor];
11751177
}
11761178

Tests/ParserTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,11 @@ public function escapedQuotationCharactersInQuotedStrings()
16181618
];
16191619
}
16201620

1621+
public function testBackslashInSingleQuotedString()
1622+
{
1623+
$this->assertSame(['foo' => 'bar\\'], $this->parser->parse("foo: 'bar\'"));
1624+
}
1625+
16211626
public function testParseMultiLineString()
16221627
{
16231628
$this->assertEquals("foo bar\nbaz", $this->parser->parse("foo\nbar\n\nbaz"));

0 commit comments

Comments
 (0)