Skip to content

Commit f1fc5fd

Browse files
committed
Restore escape sequences features
1 parent dd0f635 commit f1fc5fd

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Phug/Reader.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public function readIdentifier($prefix = null, $allowedChars = null)
747747
*
748748
* @return string|null the resulting string or null if none encountered.
749749
*/
750-
public function readString($raw = false)
750+
public function readString(array $escapeSequences = null, $raw = false)
751751
{
752752
if (!$this->peekQuote()) {
753753
return;
@@ -764,8 +764,12 @@ public function readString($raw = false)
764764

765765
//Handle escaping based on passed sequences
766766
if ($char === '\\') {
767-
//Peek the next char
768-
$string .= $this->consume(1);
767+
$nextChar = $this->consume(1);
768+
$string .= array_key_exists($nextChar, $escapeSequences ?: [])
769+
//Peek the escape sequence
770+
? $escapeSequences[$nextChar]
771+
//Peek the next char
772+
: ($raw ? $char : '').$nextChar;
769773
continue;
770774
}
771775

@@ -821,7 +825,7 @@ public function readExpression(array $breaks = null, array $brackets = null)
821825
//Append a string if any was found
822826
//Notice there can be brackets in strings, we dont want to
823827
//count those
824-
$expression .= $this->readString(true);
828+
$expression .= $this->readString(null, true);
825829

826830
if (!$this->hasLength()) {
827831
break;

0 commit comments

Comments
 (0)