Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd3eaf8

Browse files
committed
[ExpressionLanguage] Fixed collisions of character operators with object properties
- changed regex for match character operator
1 parent cdfc4ea commit dd3eaf8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Symfony/Component/ExpressionLanguage/Lexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function tokenize($expression)
7373
// strings
7474
$tokens[] = new Token(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)), $cursor + 1);
7575
$cursor += \strlen($match[0]);
76-
} elseif (preg_match('/(?<!\.)not in(?=[\s(])|\!\=\=|(?<!\.)not(?=[\s(])|(?<!\.)and(?=[\s(])|\=\=\=|\>\=|(?<!\.)or(?=[\s(])|\<\=|\*\*|\.\.|(?<!\.)in(?=[\s(])|&&|\|\||(?<!\.)matches|\=\=|\!\=|\*|~|%|\/|\>|\||\!|\^|&|\+|\<|\-/A', $expression, $match, 0, $cursor)) {
76+
} elseif (preg_match('/(?<=^|[\s(])not in(?=[\s(])|\!\=\=|(?<=^|[\s(])not(?=[\s(])|(?<=^|[\s(])and(?=[\s(])|\=\=\=|\>\=|(?<=^|[\s(])or(?=[\s(])|\<\=|\*\*|\.\.|(?<=^|[\s(])in(?=[\s(])|&&|\|\||(?<=^|[\s(])matches|\=\=|\!\=|\*|~|%|\/|\>|\||\!|\^|&|\+|\<|\-/A', $expression, $match, 0, $cursor)) {
7777
// operators
7878
$tokens[] = new Token(Token::OPERATOR_TYPE, $match[0], $cursor + 1);
7979
$cursor += \strlen($match[0]);

src/Symfony/Component/ExpressionLanguage/Resources/bin/generate_operator_regex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
$regex = [];
1717
foreach ($operators as $operator => $length) {
1818
// Collisions of character operators:
19-
// - an operator that begins with a character must not be following after dot
19+
// - an operator that begins with a character must have a space or a parenthesis before or starting at the beginning of a string
2020
// - an operator that ends with a character must be followed by a whitespace or a parenthesis
2121
$regex[] =
22-
(ctype_alpha($operator[$length - 1]) ? '(?<!\.)' : '')
22+
(ctype_alpha($operator[0]) ? '(?<=^|[\s(])' : '')
2323
.preg_quote($operator, '/')
2424
.(ctype_alpha($operator[$length - 1]) ? '(?=[\s(])' : '');
2525
}

0 commit comments

Comments
 (0)