From 08db1a4a3fb5c68c45391391801c79ee3c7b646a Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 10 Feb 2016 01:12:57 +0100 Subject: [PATCH] - bugfix {strip} must keep space on output creating smarty tags within html tags https://github.com/smarty-php/smarty/issues/177 --- change_log.txt | 3 +++ libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_internal_compile_insert.php | 4 +++- .../smarty_internal_compile_private_block_plugin.php | 4 ++-- .../smarty_internal_compile_private_function_plugin.php | 6 +++--- .../smarty_internal_compile_private_object_function.php | 5 +++-- ...smarty_internal_compile_private_registered_function.php | 5 +++-- libs/sysplugins/smarty_internal_templatecompilerbase.php | 7 +++++-- 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/change_log.txt b/change_log.txt index 40e07e6d..4f01bd2a 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.30-dev ===== (xx.xx.xx) + 10.02.2016 + - bugfix {strip} must keep space on output creating smarty tags within html tags https://github.com/smarty-php/smarty/issues/177 + 09.02.2016 - move some code from parser into compiler - reformat all code for unique style diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 644bdb54..0de3fdc9 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.30-dev/31'; + const SMARTY_VERSION = '3.1.30-dev/32'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_insert.php b/libs/sysplugins/smarty_internal_compile_insert.php index dbccbac3..5ef0ac2c 100644 --- a/libs/sysplugins/smarty_internal_compile_insert.php +++ b/libs/sysplugins/smarty_internal_compile_insert.php @@ -54,6 +54,9 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->getAttributes($compiler, $args); + //Does tag create output + $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true; + $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache); if (!$nocacheParam) { // do not compile as nocache code @@ -140,7 +143,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>"; } } else { - $compiler->has_output = true; if ($_smarty_tpl->caching && !$nocacheParam) { $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>"; } else { diff --git a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php index 758b3320..ef5682a5 100644 --- a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php +++ b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php @@ -77,8 +77,8 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi } // closing tag of block plugin, restore nocache list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, - 5)); - // This tag does create output - $compiler->has_output = true; + //Does tag create output + $compiler->has_output = isset($_params[ 'assign' ]) ? false : true; // compile code if (!isset($parameter[ 'modifier_list' ])) { $mod_pre = $mod_post = $mod_content = ''; diff --git a/libs/sysplugins/smarty_internal_compile_private_function_plugin.php b/libs/sysplugins/smarty_internal_compile_private_function_plugin.php index 36e6e9f8..c0a9b28e 100644 --- a/libs/sysplugins/smarty_internal_compile_private_function_plugin.php +++ b/libs/sysplugins/smarty_internal_compile_private_function_plugin.php @@ -45,11 +45,11 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function) { - // This tag does create output - $compiler->has_output = true; - // check and get attributes $_attr = $this->getAttributes($compiler, $args); + //Does tag create output + $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true; + if ($_attr[ 'nocache' ] === true) { $compiler->tag_nocache = true; } diff --git a/libs/sysplugins/smarty_internal_compile_private_object_function.php b/libs/sysplugins/smarty_internal_compile_private_object_function.php index 77e54cdc..422a6597 100644 --- a/libs/sysplugins/smarty_internal_compile_private_object_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_object_function.php @@ -39,6 +39,9 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co { // check and get attributes $_attr = $this->getAttributes($compiler, $args); + //Does tag create output + $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true; + if ($_attr[ 'nocache' ] === true) { $compiler->tag_nocache = true; } @@ -72,8 +75,6 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co } if (empty($_assign)) { - // This tag does create output - $compiler->has_output = true; $output = "\n"; } else { $output = "assign({$_assign},{$return});?>\n"; diff --git a/libs/sysplugins/smarty_internal_compile_private_registered_function.php b/libs/sysplugins/smarty_internal_compile_private_registered_function.php index 88639336..c1cf7086 100644 --- a/libs/sysplugins/smarty_internal_compile_private_registered_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_registered_function.php @@ -36,10 +36,11 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag) { - // This tag does create output - $compiler->has_output = true; // check and get attributes $_attr = $this->getAttributes($compiler, $args); + //Does tag create output + $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true; + if ($_attr[ 'nocache' ]) { $compiler->tag_nocache = true; } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 8fe22a8d..6d3f0802 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -794,8 +794,11 @@ abstract class Smarty_Internal_TemplateCompilerBase if ((string) $text != '') { $store = array(); $_store = 0; - $_offset = 0; + $space = ''; if ($this->parser->strip) { + $space = $this->has_output && preg_match('/^\040|\011/', $text) ? ' ' : ''; + $this->has_output = false; + if (strpos($text, '<') !== false) { // capture html elements not to be messed with $_offset = 0; @@ -836,7 +839,7 @@ abstract class Smarty_Internal_TemplateCompilerBase $text = preg_replace($this->stripRegEx, '', $text); } } - return new Smarty_Internal_ParseTree_Text($text); + return new Smarty_Internal_ParseTree_Text($space . $text); } return null; }