From d5c56c5d503ea4b12852866e2d3b956e92a92aea Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 20:02:03 -0500 Subject: [PATCH 1/3] [ticket/11724] Support "ELSE IF" and "ELSEIF" in the same way PHPBB3-11724 --- phpBB/phpbb/template/twig/lexer.php | 3 ++- tests/template/template_test.php | 7 +++++++ tests/template/templates/if.html | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 4f88147542..1a640e559e 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -236,7 +236,8 @@ 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); + // (ELSE)?\s?IF; match IF|ELSEIF|ELSE IF; replace ELSE IF with ELSEIF + return preg_replace_callback('##', $callback, $code); } /** diff --git a/tests/template/template_test.php b/tests/template/template_test.php index dd9ba21c26..2a40107d90 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -62,6 +62,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), '1!false', ), + array( + 'if.html', + array('S_OTHER_OTHER_VALUE' => true), + array(), + array(), + '|S_OTHER_OTHER_VALUE|!false', + ), array( 'if.html', array('S_VALUE' => false, 'S_OTHER_VALUE' => true), diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index c010aff7fa..f6ab6e575a 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -2,6 +2,8 @@ 1 2 + +|S_OTHER_OTHER_VALUE| 03 From 0215e0bd95104c628cf084e1be0df72b2752346c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 28 Jul 2013 21:31:12 -0500 Subject: [PATCH 2/3] [ticket/11724] Replace spaces with tabs PHPBB3-11724 --- phpBB/phpbb/template/twig/lexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 1a640e559e..7cb84167bf 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -237,7 +237,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); // (ELSE)?\s?IF; match IF|ELSEIF|ELSE IF; replace ELSE IF with ELSEIF - return preg_replace_callback('##', $callback, $code); + return preg_replace_callback('##', $callback, $code); } /** From 38a7aac0cceee521fbf2550750a85b4d6bf80ec1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 28 Aug 2013 12:29:01 -0500 Subject: [PATCH 3/3] [ticket/11724] Handle ELSE IF separately PHPBB3-11724 --- phpBB/phpbb/template/twig/lexer.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 7cb84167bf..d576316e89 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -221,6 +221,12 @@ class phpbb_template_twig_lexer extends Twig_Lexer */ protected function fix_if_tokens($code) { + // Replace ELSE IF with ELSEIF + $code = preg_replace('##', '', $code); + + // 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); + $callback = function($matches) { $inner = $matches[2]; @@ -233,11 +239,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer return ""; }; - // 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); - - // (ELSE)?\s?IF; match IF|ELSEIF|ELSE IF; replace ELSE IF with ELSEIF - return preg_replace_callback('##', $callback, $code); + return preg_replace_callback('##', $callback, $code); } /**