From 62e81d174d9d3dbd78baea36425720ed0fdaffb1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 29 Aug 2013 09:19:14 -0500 Subject: [PATCH 1/3] [ticket/11816] Fix define/loop checks in IF statements containing parenthesis PHPBB3-11816 --- phpBB/phpbb/template/twig/lexer.php | 8 ++++---- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 3534311b7a..719066b659 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -223,13 +223,13 @@ class phpbb_template_twig_lexer extends Twig_Lexer { $inner = $matches[2]; // 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 - $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 - $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 ""; }; @@ -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) $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); - return preg_replace_callback('##', $callback, $code); + return preg_replace_callback('##', $callback, $code); } /** diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0a6b680100..0473218353 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case 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(), - "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 66e874ca63..12842ad387 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,6 +7,9 @@ $VALUE != 'abc' $VALUE == 'abc' + +($VALUE == 'abc') + {$INCLUDED_VALUE} {$VALUE} From 0c5a39a3ed382bef37005e59de66120e3cf205fa Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 2 Sep 2013 15:50:34 -0500 Subject: [PATCH 2/3] [ticket/11816] Test !$DEFINITION PHPBB3-11816 --- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0473218353..94289842df 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case 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(), - "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 12842ad387..e96d14e813 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -10,6 +10,9 @@ $VALUE == 'abc' ($VALUE == 'abc') + +(!$DOESNT_EXIST) + {$INCLUDED_VALUE} {$VALUE} From 11317ef261c7811ea137d19ee38593d289ea6150 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 6 Sep 2013 09:04:40 -0500 Subject: [PATCH 3/3] [ticket/11816] !$DOESNT_EXIST test PHPBB3-11816 --- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 94289842df..b41193d59e 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case 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(), - "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index e96d14e813..a56fece912 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -10,6 +10,9 @@ $VALUE == 'abc' ($VALUE == 'abc') + +!$DOESNT_EXIST + (!$DOESNT_EXIST)