From e19bfe73a0c4b58b36fbdd41c17868313c20fb28 Mon Sep 17 00:00:00 2001 From: mohrt Date: Thu, 17 Apr 2003 15:20:19 +0000 Subject: [PATCH] corrected output with Smarty comments --- NEWS | 3 ++- libs/Smarty_Compiler.class.php | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index c1f1f1bb..46702b23 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ - - fixed bug with {strip} and PHP tag newlines (Monte) + - corrected output with smarty comments (Monte) + - corrected output with {strip} and PHP tag newlines (Monte) - added possibility to register function-callbacks as "array(&$obj, 'method)" this affects register_function(), -block, -compiler_function, -modifier, -prefilter, -postfilter, -outputfilter-functions() and $cache_handler_func diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 2f59106c..7531d643 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -238,25 +238,33 @@ class Smarty_Compiler extends Smarty { } /* Annihilate the comments. */ - $template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se", - "'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'", + + $_comment_search = array( + "!(\r|\r\n|\n)({$ldq})\*(.*?)\*({$rdq})(\r|\r\n|\n)!s", + "!({$ldq})\*(.*?)\*({$rdq})!s"); + $_comment_replace = array( + '\\1', + ''); + + $template_source = preg_replace($_comment_search, + $_comment_replace, $template_source); /* Pull out the literal blocks. */ - preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match); - $this->_literal_blocks = $match[1]; + preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $_match); + $this->_literal_blocks = $_match[1]; $template_source = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source); /* Pull out the php code blocks. */ - preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $match); - $this->_php_blocks = $match[1]; + preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $_match); + $this->_php_blocks = $_match[1]; $template_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $template_source); /* Gather all template tags. */ - preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $match); - $template_tags = $match[1]; + preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $_match); + $template_tags = $_match[1]; /* Split content by template tags to obtain non-template content. */ $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source); @@ -379,10 +387,6 @@ class Smarty_Compiler extends Smarty { */ function _compile_tag($template_tag) { - - /* Matched comment. */ - if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') - return ''; /* Split tag into two three parts: command, command modifiers and the arguments. */ if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp