bug #11439 [ExpressionLanguage] Fixed double quoted string literals containing sharps (pylebecq)

This PR was merged into the 2.4 branch.

Discussion
----------

[ExpressionLanguage] Fixed double quoted string literals containing sharps

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11433
| License       | MIT
| Doc PR        | n/a

Commits
-------

0c2622e [ExpressionLanguage] Fixed an issue with # characters in double quoted string literals
This commit is contained in:
Fabien Potencier 2014-07-23 10:01:19 +02:00
commit 0032abd618
2 changed files with 9 additions and 1 deletions

View File

@ -69,7 +69,7 @@ class Lexer
$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
++$cursor;
} elseif (preg_match('/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As', $expression, $match, null, $cursor)) {
} elseif (preg_match('/"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As', $expression, $match, null, $cursor)) {
// strings
$tokens[] = new Token(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)), $cursor + 1);
$cursor += strlen($match[0]);

View File

@ -78,6 +78,14 @@ class LexerTest extends \PHPUnit_Framework_TestCase
array(new Token('operator', '..', 1)),
'..',
),
array(
array(new Token('string', '#foo', 1)),
"'#foo'",
),
array(
array(new Token('string', '#foo', 1)),
'"#foo"',
),
);
}
}