From 01a2622dc6b9910b2f4a3d7c77e7b06b51584bc0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 15:49:49 +0100 Subject: [PATCH 1/3] [ticket/11323] Correctly treat variables in template defines Previously, any template variables that were used when defining a variable were treated as strings. This is a regression to phpBB 3.0. With this patch the template variables will be properly parsed. PHPBB3-11323 --- phpBB/includes/template/filter.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index f73ad28ba1..93bacd9c1e 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -830,10 +830,11 @@ class phpbb_template_filter extends php_user_filter */ private function compile_tag_define($tag_args, $op) { + $add_quote = true; $match = array(); - preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (.*?))?$#', $tag_args, $match); + preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (\'?)([^\']*)(\'?))?$#', $tag_args, $match); - if (empty($match[2]) || (!isset($match[3]) && $op)) + if (empty($match[2]) || (!isset($match[4]) && $op)) { return ''; } @@ -843,7 +844,12 @@ class phpbb_template_filter extends php_user_filter return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ');'; } - $parsed_statement = implode(' ', $this->compile_expression($match[3])); + if ($match[3] && $match[5] && substr($match[4], 0, 1) == '{' && substr($match[4], -1, 1) == '}') + { + $match[4] = substr($match[4], 1, -1); + $add_quote = false; + } + $parsed_statement = ($add_quote) ? "'" . implode(' ', $this->compile_expression($match[4])) . "'" : implode(' ', $this->compile_expression($match[4])); return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $parsed_statement . ';'; } From dd5963eabb17b29fc4abc98ea0cb95357fe253bb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 15:59:15 +0100 Subject: [PATCH 2/3] [ticket/11323] Enable tests for inclusion of defined variables PHPBB3-11323 --- tests/template/template_test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index f43157775a..56cc7a9de5 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -197,8 +197,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('loop'), '', ), - /* Currently fail on develop: - http://tracker.phpbb.com/browse/PHPBB3-11323 array( 'include_define_variable.html', array('VARIABLE' => 'variable.html'), @@ -213,7 +211,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'value', ), - */ /* no top level nested loops array( 'loop_vars.html', From 1ebb17c698ce17147abec0af5048ac522014cf45 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 26 Feb 2013 21:43:39 +0100 Subject: [PATCH 3/3] [ticket/11323] Reduce additional code and revert regex to previous one PHPBB3-11323 --- phpBB/includes/template/filter.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 93bacd9c1e..9e8ad2fef0 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -830,11 +830,10 @@ class phpbb_template_filter extends php_user_filter */ private function compile_tag_define($tag_args, $op) { - $add_quote = true; $match = array(); - preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (\'?)([^\']*)(\'?))?$#', $tag_args, $match); + preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (.*?))?$#', $tag_args, $match); - if (empty($match[2]) || (!isset($match[4]) && $op)) + if (empty($match[2]) || (!isset($match[3]) && $op)) { return ''; } @@ -844,12 +843,18 @@ class phpbb_template_filter extends php_user_filter return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ');'; } - if ($match[3] && $match[5] && substr($match[4], 0, 1) == '{' && substr($match[4], -1, 1) == '}') + /* + * Define tags that contain template variables (enclosed in curly brackets) + * need to be treated differently. + */ + if (substr($match[3], 1, 1) == '{' && substr($match[3], -2, 1) == '}') { - $match[4] = substr($match[4], 1, -1); - $add_quote = false; + $parsed_statement = implode(' ', $this->compile_expression(substr($match[3], 2, -2))); + } + else + { + $parsed_statement = implode(' ', $this->compile_expression($match[3])); } - $parsed_statement = ($add_quote) ? "'" . implode(' ', $this->compile_expression($match[4])) . "'" : implode(' ', $this->compile_expression($match[4])); return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $parsed_statement . ';'; }