Skip to content

Commit 5663e6a

Browse files
🐛 Fix string with /
1 parent 8550227 commit 5663e6a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

TwigCS/src/Token/Tokenizer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class Tokenizer
2020
private const STATE_INTERPOLATION = 4;
2121
private const STATE_COMMENT = 5;
2222

23+
private const SQ_STRING_PART = '[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*';
24+
private const DQ_STRING_PART = '[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*';
25+
2326
private const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A';
2427
private const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A';
25-
private const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As';
28+
private const REGEX_STRING = '/"('.self::DQ_STRING_PART.')"|\'('.self::SQ_STRING_PART.')\'/As';
29+
private const REGEX_DQ_STRING_PART = '/'.self::DQ_STRING_PART.'/As';
2630
private const REGEX_DQ_STRING_DELIM = '/"/A';
27-
private const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As';
2831
private const PUNCTUATION = '()[]{}:.,|';
2932

30-
// TODO: Il faut surement changer les regex pour que "a#" et "a" soient traités de la même manière
31-
// Car actuellement le second est DQ string (sans interpolation) alors que le premier est string
32-
3333
/**
3434
* @var array
3535
*/
@@ -408,7 +408,7 @@ protected function lexDqString(): void
408408
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor)
409409
&& strlen($match[0]) > 0
410410
) {
411-
$this->pushToken(Token::STRING_TYPE, stripcslashes($match[0]));
411+
$this->pushToken(Token::STRING_TYPE, $match[0]);
412412
$this->moveCursor($match[0]);
413413
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
414414
$bracket = array_pop($this->bracketsAndTernary);
@@ -667,7 +667,7 @@ protected function lexPunctuation(): void
667667
*/
668668
protected function lexString(string $string): void
669669
{
670-
$this->pushToken(Token::STRING_TYPE, addcslashes(stripcslashes($string), '\\'));
670+
$this->pushToken(Token::STRING_TYPE, $string);
671671
$this->moveCursor($string);
672672
}
673673
}

0 commit comments

Comments
 (0)