Bugfix for comments

From: Date: Sat, 22 Sep 2001 14:44:11 +0000
Subject: Bugfix for comments
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1529@lists.php.net to get a copy of this message
The new code (v 1.4.5) that allows commenting out Smarty tags is a little buggy. Line numbering does not always work. Try this short template: {bad tag on line 1} {* line 2 line 3 line 4 *} The warning is reported for line 3! Actually, the more lines you have in comments appearing after a bugged tag, the more offset you get. FIX: 1) In Smarty_compiler.class.php, function _compile_file(), replace the following lines: /* Annihilate the comments. */ if (preg_match_all("!{$ldq}\*.*?\*{$rdq}!s", $template_source, $match)) { foreach ($match[0] as $comment) $this->_current_line_no += substr_count($comment, "\n"); $template_source = preg_replace("!{$ldq}\*.*?\*{$rdq}!s", '', $template_source); } .. with the following lines : /* Annihilate the comments. */ $template_source = preg_replace("!({$ldq})(\*.*?\*)({$rdq})!se", "'\\1*'.str_repeat(\"\n\",substr_count('\\2', \"\n\")) .'*\\3'", $template_source ); 2) add the following (old code from v1.4.4) at the top of function _compile_tag() : /* Matched comment. */ if ($template_tag{0} == '*' && $template_tag{strlen($template_tag)- 1} == '*') return ''; The replacement code in step 1 wipes out everything within the comment tag, but keeps the linebreaks. Same number of lines, and the comment is still left as a tag to handle. Step 2 then takes care of the comment tag (now empty) just the way it was before 1.4.5. /Anders

« previous php.smarty.general (#1529) next »