From bd2abcbbcd5d1d3d018144157c44c06fd20ea2e9 Mon Sep 17 00:00:00 2001 From: messju Date: Sun, 30 Jan 2005 21:54:39 +0000 Subject: [PATCH] fixed handling of hashed opening php-tags inside strip-blocks (reported by titi_rafa) --- NEWS | 1 + libs/Smarty_Compiler.class.php | 37 ++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index b16ec46a..f5d3069e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ + - fix handling of hashed opening php-tags inside strip-blocks (messju) - change escape:url use rawurlencode() instead of urlencode() (messju) - make $smarty.const.FOO compile to "FOO", and not to "constant('foo')". this is less code and a little faster execution. note that undefined diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 0d3091c1..dbb13158 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -318,6 +318,32 @@ class Smarty_Compiler extends Smarty { return; } + /* Reformat $text_blocks between 'strip' and '/strip' tags, + removing spaces, tabs and newlines. */ + $strip = false; + for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { + if ($compiled_tags[$i] == '{strip}') { + $compiled_tags[$i] = ''; + $strip = true; + } + if ($strip) { + /* strip all $text_blocks before the next '/strip' */ + for ($j = $i + 1; $j < $for_max; $j++) { + /* remove leading and trailing whitespaces of each line */ + $text_blocks[$j] = preg_replace('!\s+$|^\s+!m', '', $text_blocks[$j]); + /* remove carriage return and newline between each line */ + $text_blocks[$j] = preg_replace('![\r\n]+!m', '', $text_blocks[$j]); + $text_blocks[$j] = ""\'", "\\"=>"\\\\")) . "'; ?>"; + if ($compiled_tags[$j] == '{/strip}') { + $compiled_tags[$j] = "\n"; /* slurped by php, but necessary + if a newline is following the closing strip-tag */ + $strip = false; + $i = $j; + break; + } + } + } + } $compiled_content = ''; /* Interleave the compiled contents and text blocks to get the final result. */ @@ -330,17 +356,6 @@ class Smarty_Compiler extends Smarty { } $compiled_content .= $text_blocks[$i]; - /* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */ - if (preg_match_all("~{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}~s", $compiled_content, $_match)) { - $strip_tags = $_match[0]; - $strip_tags_modified = preg_replace("~{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+~m", '', $strip_tags); - $strip_tags_modified = preg_replace('~[\r\n]+~m', '', $strip_tags_modified); - for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++) - $compiled_content = preg_replace("~{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}~s", - $this->_quote_replace($strip_tags_modified[$i]), - $compiled_content, 1); - } - // remove \n from the end of the file, if any if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) { $compiled_content = substr($compiled_content, 0, -1);