mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
allowed operators that contain whitespaces to have more than one whitespace
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
* 1.14.2 (2013-XX-XX)
|
||||
|
||||
* n/a
|
||||
* allowed operators that contain whitespaces to have more than one whitespace
|
||||
|
||||
* 1.14.1 (2013-10-15)
|
||||
|
||||
|
||||
+8
-3
@@ -228,7 +228,7 @@ class Twig_Lexer implements Twig_LexerInterface
|
||||
|
||||
// operators
|
||||
if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) {
|
||||
$this->pushToken(Twig_Token::OPERATOR_TYPE, $match[0]);
|
||||
$this->pushToken(Twig_Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
|
||||
$this->moveCursor($match[0]);
|
||||
}
|
||||
// names
|
||||
@@ -377,10 +377,15 @@ class Twig_Lexer implements Twig_LexerInterface
|
||||
// an operator that ends with a character must be followed by
|
||||
// a whitespace or a parenthesis
|
||||
if (ctype_alpha($operator[$length - 1])) {
|
||||
$regex[] = preg_quote($operator, '/').'(?=[\s()])';
|
||||
$r = preg_quote($operator, '/').'(?=[\s()])';
|
||||
} else {
|
||||
$regex[] = preg_quote($operator, '/');
|
||||
$r = preg_quote($operator, '/');
|
||||
}
|
||||
|
||||
// an operator with a space can be any amount of whitespaces
|
||||
$r = preg_replace('/\s+/', '\s+', $r);
|
||||
|
||||
$regex[] = $r;
|
||||
}
|
||||
|
||||
return '/'.implode('|', $regex).'/A';
|
||||
|
||||
@@ -4,9 +4,14 @@ Twig supports the "starts with" operator
|
||||
{{ 'foo' starts with 'f' ? 'OK' : 'KO' }}
|
||||
{{ not ('foo' starts with 'oo') ? 'OK' : 'KO' }}
|
||||
{{ not ('foo' starts with 'foowaytoolong') ? 'OK' : 'KO' }}
|
||||
{{ 'foo' starts with 'f' ? 'OK' : 'KO' }}
|
||||
{{ 'foo' starts
|
||||
with 'f' ? 'OK' : 'KO' }}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXPECT--
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
|
||||
Reference in New Issue
Block a user