diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php
index c25e52a74..20e29281b 100644
--- a/classes/template/TemplateHandler.class.php
+++ b/classes/template/TemplateHandler.class.php
@@ -555,6 +555,10 @@ class TemplateHandler
switch($stmt)
{
case 'cond':
+ if (preg_match('/^\$[\\\\\w\[\]\'":>-]+$/i', $expr))
+ {
+ $expr = "$expr ?? false";
+ }
$nodes[$idx - 1] .= "";
break;
case 'loop':
@@ -779,11 +783,11 @@ class TemplateHandler
if ($filter_option)
{
$filter_option = $this->_applyEscapeOption($filter_option, $escape_option);
- $var = "'' . {$var} . ''";
+ $var = "'' . ($var) . ''";
}
else
{
- $var = "'' . {$var} . ''";
+ $var = "'' . ($var) . ''";
}
$escape_option = 'noescape';
break;
@@ -1027,6 +1031,11 @@ class TemplateHandler
*/
private function _applyEscapeOption($str, $escape_option)
{
+ if (preg_match('/^\$[\\\\\w\[\]\'":>-]+$/i', $str))
+ {
+ $str = "$str ?? ''";
+ }
+
switch($escape_option)
{
case 'escape':
diff --git a/tests/unit/classes/TemplateHandlerTest.php b/tests/unit/classes/TemplateHandlerTest.php
index 3dd3151f1..f5006943d 100644
--- a/tests/unit/classes/TemplateHandlerTest.php
+++ b/tests/unit/classes/TemplateHandlerTest.php
@@ -21,7 +21,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// cond
array(
'Link1say, hello',
- '?>Link1cond){ ?>say, hello'
+ '?>Link1cond ?? false){ ?>say, hello'
),
// cond
array(
@@ -51,7 +51,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// ~
array(
'LinkHello, {$world}',
- '?>Linkcond){ ?>Hello, world ?>'
+ '?>Linkcond){ ?>Hello, world ?? \'\' ?>'
),
// ~ ~
array(
@@ -71,12 +71,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// ~
array(
'
item{$key} : {$val}',
- PHP_EOL . 'if($__Context->arr)foreach($__Context->arr as $__Context->key=>$__Context->val){ ?>itemkey ?> : val ?>'
+ PHP_EOL . 'if($__Context->arr)foreach($__Context->arr as $__Context->key=>$__Context->val){ ?>itemkey ?? \'\' ?> : val ?? \'\' ?>'
),
// ~
array(
'{$v->text}',
- PHP_EOL.'while($__Context->item=$__Context->list->getItem()){ ?>v->text ?>'
+ PHP_EOL.'while($__Context->item=$__Context->list->getItem()){ ?>v->text ?? \'\' ?>'
),
// ~ ~ ~ ~
array(
@@ -146,7 +146,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// self-closing tag
array(
'',
- PHP_EOL . 'if($__Context->foo){ ?>'
+ PHP_EOL . 'if($__Context->foo ?? false){ ?>'
),
// relative path1
array(
@@ -161,7 +161,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// error case
array(
'
',
- PHP_EOL . 'if($__Context->layout_info->logo_image){ ?>
'
+ PHP_EOL . 'if($__Context->layout_info->logo_image ?? false){ ?>
'
),
// error case - ignore stylesheets
array(
@@ -186,7 +186,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// issue 135
array(
'{$key}
Loop block {$val}
',
- PHP_EOL . '$__loop_tmp=$__Context->_m_list_all;if($__loop_tmp)foreach($__loop_tmp as $__Context->key=>$__Context->val){ ?>key ?>
Loop block val ?>
'
+ PHP_EOL . '$__loop_tmp=$__Context->_m_list_all;if($__loop_tmp)foreach($__loop_tmp as $__Context->key=>$__Context->val){ ?>key ?? \'\' ?>
Loop block val ?? \'\' ?>
'
),
// issue 136
array(
@@ -206,12 +206,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// issue 183
array(
'',
- '?>vvvls;if($__loop_tmp)foreach($__loop_tmp as $__Context->vvv){ ?>| vvv ?> |
'."\n".'| C | D |
'
+ '?>vvvls;if($__loop_tmp)foreach($__loop_tmp as $__Context->vvv){ ?>| vvv ?? \'\' ?> |
'."\n".'| C | D |
'
),
// issue 512 - ignores