cvs: smarty /libs Smarty_Compiler.class.php

From: Date: Fri, 23 Feb 2007 15:41:56 +0000
Subject: cvs: smarty /libs Smarty_Compiler.class.php
Groups: php.smarty.cvs 
Request: Send a blank email to php-smarty-cvs+get-2202@lists.php.net to get a copy of this message
mohrt Fri Feb 23 15:41:56 2007 UTC Modified files: /smarty/libs Smarty_Compiler.class.php Log: fix situation when no compiled tags are present http://cvs.php.net/viewvc.cgi/smarty/libs/Smarty_Compiler.class.php?r1=1.388&r2=1.389&diff_format=u Index: smarty/libs/Smarty_Compiler.class.php diff -u smarty/libs/Smarty_Compiler.class.php:1.388 smarty/libs/Smarty_Compiler.class.php:1.389 --- smarty/libs/Smarty_Compiler.class.php:1.388 Fri Feb 23 14:24:10 2007 +++ smarty/libs/Smarty_Compiler.class.php Fri Feb 23 15:41:56 2007 @@ -26,7 +26,7 @@ * @package Smarty */ -/* $Id: Smarty_Compiler.class.php,v 1.388 2007/02/23 14:24:10 mohrt Exp $ */ +/* $Id: Smarty_Compiler.class.php,v 1.389 2007/02/23 15:41:56 mohrt Exp $ */ /** * Template compiling class @@ -352,15 +352,17 @@ } } $compiled_content = ''; - + $tmp_id = '{'.md5(uniqid(rand(), true)).'}'; /* Interleave the compiled contents and text blocks to get the final result. */ for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { + if ($compiled_tags[$i] == '') { // tag result empty, remove first newline from following text block $text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]); } + // replace legit PHP tags with placeholder $text_blocks[$i] = str_replace('<?',$tmp_id,$text_blocks[$i]); $compiled_tags[$i] = str_replace('<?',$tmp_id,$compiled_tags[$i]); @@ -368,12 +370,15 @@ $compiled_content .= $text_blocks[$i].$compiled_tags[$i]; } $compiled_content .= $text_blocks[$i]; - - // escape created php tags - $compiled_content = str_replace('<?',"<?php echo '<?' ?>\n",$compiled_content); - // unescape legit tags - $compiled_content = str_replace($tmp_id,'<?',$compiled_content); + if(count($compiled_tags)>0) + { + // escape created php tags + $compiled_content = str_replace('<?',"<?php echo '<?' ?>\n",$compiled_content); + // recover legit tags + $compiled_content = str_replace($tmp_id,'<?',$compiled_content); + } + // remove \n from the end of the file, if any if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) { $compiled_content = substr($compiled_content, 0, -1);

« previous php.smarty.cvs (#2202) next »