From f97411b91143a0c75ef0ecec3ff03fc36a879728 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 25 Apr 2011 13:03:55 -0400 Subject: [PATCH] [feature/template-engine] Corrected miscompilation of loop size constructs. PHPBB3-9726 --- phpBB/includes/template_compile.php | 2 +- tests/template/template_test.php | 7 +++++ tests/template/templates/loop_size.html | 39 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/template/templates/loop_size.html diff --git a/phpBB/includes/template_compile.php b/phpBB/includes/template_compile.php index cba402f83b..9a8bc05343 100644 --- a/phpBB/includes/template_compile.php +++ b/phpBB/includes/template_compile.php @@ -588,7 +588,7 @@ class phpbb_template_filter extends php_user_filter // Add the block reference for the last child. $varref .= "['" . $blocks[0] . "']"; } - $token = "isset($varref) && sizeof($varref)"; + $token = "(isset($varref) ? sizeof($varref) : 0)"; } break; diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 5c43fe656e..5a21d2f69c 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -288,6 +288,13 @@ class phpbb_template_template_test extends phpbb_test_case // I don't completely understand this output, hopefully it's correct "top-level content\nouter\n\ninner z\nfirst row\n\ninner zz", ), + array( + 'loop_size.html', + array(), + array('loop' => array(array()), 'empty_loop' => array()), + array(), + "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", + ), ); } diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html new file mode 100644 index 0000000000..f1938441df --- /dev/null +++ b/tests/template/templates/loop_size.html @@ -0,0 +1,39 @@ + + nonexistent + + + + nonexistent = 0 + + + + ! nonexistent + + + + empty + + + + empty = 0 + + + + ! empty + + + + loop + + + + loop = 0 + + + + ! loop + + + + in loop +