allowed operators that contain whitespaces to have more than one whitespace

This commit is contained in:
Fabien Potencier
2013-10-27 10:56:11 +01:00
parent 5eb8373b1c
commit 724dc61bea
3 changed files with 14 additions and 4 deletions
+1 -1
View File
@@ -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
View File
@@ -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