From cc4d8fa1a07e18f00951a921041e37c87015dcb2 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Thu, 17 May 2018 16:04:48 +0200 Subject: [PATCH] - bugfix strip-block produces different output in Smarty v3.1.32 https://github.com/smarty-php/smarty/issues/436 --- change_log.txt | 3 ++- libs/Smarty.class.php | 2 +- .../smarty_internal_templatecompilerbase.php | 26 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/change_log.txt b/change_log.txt index c180868d..982a7e8e 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@ ===== 3.1.33-dev-4 ===== 17.05.2018 - - Smarty::compileAllTemplates ignores `$extension` parameter https://github.com/smarty-php/smarty/issues/437 + - bugfix strip-block produces different output in Smarty v3.1.32 https://github.com/smarty-php/smarty/issues/436 + - bugfix Smarty::compileAllTemplates ignores `$extension` parameter https://github.com/smarty-php/smarty/issues/437 https://github.com/smarty-php/smarty/pull/438 - improvement do not compute total property in {foreach} if not needed https://github.com/smarty-php/smarty/issues/443 - bugfix plugins may not be loaded when setMergeCompiledIncludes is true https://github.com/smarty-php/smarty/issues/435 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index ad52cbc6..4d307547 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.33-dev-4'; + const SMARTY_VERSION = '3.1.33-dev-5'; /** * define variable scopes */ diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index be3647bd..f414e1d0 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -618,7 +618,7 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public function processText($text) { - if ((string)$text !== '') { + if ((string) $text != '') { $store = array(); $_store = 0; if ($this->parser->strip) { @@ -626,39 +626,37 @@ abstract class Smarty_Internal_TemplateCompilerBase // capture html elements not to be messed with $_offset = 0; if (preg_match_all('#(]*>.*?]*>)|(]*>.*?]*>)|(]*>.*?]*>)#is', - $text, - $matches, - PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { + $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { foreach ($matches as $match) { $store[] = $match[ 0 ][ 0 ]; $_length = strlen($match[ 0 ][ 0 ]); $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); + $_offset += $_length - strlen($replace); - ++$_store; + $_store ++; } } $expressions = array(// replace multiple spaces between tags by a single space - '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', + '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', // remove newline between tags - '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', + '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', // remove multiple spaces between attributes (but not in attribute values!) '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', - '#>[\040\011]+$#Ss' => '> ', - '#>[\040\011]*[\n]\s*$#Ss' => '>', - $this->stripRegEx => '',); + '#>[\040\011]+$#Ss' => '> ', '#>[\040\011]*[\n]\s*$#Ss' => '>', + $this->stripRegEx => '',); + $text = preg_replace(array_keys($expressions), array_values($expressions), $text); $_offset = 0; - if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', - $text, - $matches, + if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { foreach ($matches as $match) { $_length = strlen($match[ 0 ][ 0 ]); $replace = $store[ $match[ 1 ][ 0 ] ]; $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); + $_offset += strlen($replace) - $_length; - ++$_store; + $_store ++; } } } else {