[ticket/11816] Fix define/loop checks in IF statements containing parenthesis

PHPBB3-11816
This commit is contained in:
Nathan Guse 2013-08-29 09:19:14 -05:00
parent dcf82d9a5a
commit 62e81d174d
3 changed files with 8 additions and 5 deletions

View file

@ -223,13 +223,13 @@ class phpbb_template_twig_lexer extends Twig_Lexer
{ {
$inner = $matches[2]; $inner = $matches[2];
// Replace $TEST with definition.TEST // Replace $TEST with definition.TEST
$inner = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $inner); $inner = preg_replace('#(\s\(?!?)\$([a-zA-Z_0-9]+)#', '$1definition.$2', $inner);
// Replace .foo with loops.foo|length // Replace .foo with loops.foo|length
$inner = preg_replace('#\s\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', ' loops.$1|length$2', $inner); $inner = preg_replace('#(\s\(?!?)\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', '$1loops.$2|length$3', $inner);
// Replace .foo.bar with foo.bar|length // Replace .foo.bar with foo.bar|length
$inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', ' $1|length$2', $inner); $inner = preg_replace('#(\s\(?!?)\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', '$1$2|length$3', $inner);
return "<!-- {$matches[1]}IF{$inner}-->"; return "<!-- {$matches[1]}IF{$inner}-->";
}; };
@ -237,7 +237,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer
// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) // Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces)
$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code);
return preg_replace_callback('#<!-- (ELSE)?IF((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#', $callback, $code); return preg_replace_callback('#<!-- (ELSE)?IF((.*) \(?!?[\$|\.]([^\s]+)(.*))-->#', $callback, $code);
} }
/** /**

View file

@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(), array(),
array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
array(), array(),
"xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?",
), ),
array( array(
'define_advanced.html', 'define_advanced.html',

View file

@ -7,6 +7,9 @@ $VALUE != 'abc'
<!-- ELSEIF $VALUE == 'abc' --> <!-- ELSEIF $VALUE == 'abc' -->
$VALUE == 'abc' $VALUE == 'abc'
<!-- ENDIF --> <!-- ENDIF -->
<!-- IF ($VALUE == 'abc') -->
($VALUE == 'abc')
<!-- ENDIF -->
<!-- INCLUDE define_include.html --> <!-- INCLUDE define_include.html -->
{$INCLUDED_VALUE} {$INCLUDED_VALUE}
{$VALUE} {$VALUE}