Re: [SMARTY-DEV] strip problem again

From: Date: Mon, 01 Sep 2003 12:44:59 +0000
Subject: Re: [SMARTY-DEV] strip problem again
References: 1 2 3 4  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1833@lists.php.net to get a copy of this message
On Mon, Sep 01, 2003 at 12:58:57PM +0200, Jan Rosier wrote: > Ah {strip} again ;-) > > I will try to explain what I found out before. Hope this helps... > > In older versions of Smarty where {strip} isn't a block function, {strip} > eats to many spaces. > See example in > > http://lists.php.net/article.php?group=php.smarty.dev&article=1216 > > Template: > {strip} > <P> > {$firstname} {$lastname} > </P> > {/strip} > > Compiled before strip: > <P> > <?php echo $this->_tpl_vars['firstname']; ?> > <?php echo $this->_tpl_vars['lastname']; ?> > </P> > > Followed by strip, which first remove leading and trailing spaces and then > remove the newlines > Result: > <P><?php echo $this->_tpl_vars['firstname']; ?><?php echo > $this->_tpl_vars['lastname']; ?></P> > > Now the space between firstname and lastname is gone => unwanted > > Changing line 396 in Smarty_Compiler.class.php v2.5.0 to "<?php echo > $_return; ?>"; has the following effect on the compiled template before > strip: > <P> > <?php echo $this->_tpl_vars['firstname']; ?> <?php echo > $this->_tpl_vars['lastname']; ?> > </P> > Now strip doesn't remove the spaces before lastname (no leading spaces). The > output now will also have the space between firstname and lastname. This is > correct however this change also effects the line numbering for the error > reporting of Smarty => unwanted and it affects the newlines that make it from the source-template to the compiled output: {foo}<-- this newline will be chomped by php if the compiled line "ends" on "?>" and not on "?>\n" {bar} > The following change to the strip regex fixed the problem for my > > $_strip_search = array( > '%(<\?php echo .*?; \?>)\n%', // remove newlines > after PHP close tags of the echo statments > "!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", // remove leading/trailing > space chars > '%[\r\n]+%m', // remove CRs and newlines > '%(<\?php echo .*?; \?>)%' // put the newlines > back after PHP close tags > ); > $_strip_replace = array( > '\\1', > '', > '', > '\\1' . "\n" > ); this looks great to me. my solution here was: - everywhere where "?>\n" is printed in the template: print "?>?>" instead (so there are no additional \n that would irritate {strip} ) - make strip as it was in 2.5.0 (don't remove or insert newlines, take them literally) - after handling {strip}-blocks, before returning $compiled_content: replace "?>?>" by "?>\n" my version breaks when there is already a "?>?>" in $compiled_content, of course. this is never emitted by Smarty_Compiler and never passed through literally from the source-template, but {php} echo "?>?>"; {/php} would be a case where the ?>?> is replaced errornously, even when no {strip} is used at all. :( i think i like your version much better than mine :) there are still cases where it above breaks, for example: {strip} huhu{foo->bar assign=bar} huhu {/strip} gives: huhuhuhu (the " " is stripped errornously) reason: there is an addtional "\n" emitted after the "?>", but no echo before it. but i think these cases can be handled accordingly (by not emitting the "\n" in the first place :) right now {strip} is the last outstanding issue to me before 2.6.0-RC2. so i hope to find time to fix this soon. many thanks for your input. greetings messju > Greetings, > Jan Rosier > > * To many time we confuse motion with progress. - Cyclops * > > > ----- Original Message ----- > From: "Konstantin" <checat@pochtamt.ru> > To: "messju mohr" <messju@lammfellpuschen.de> > Cc: <smarty-dev@lists.php.net> > Sent: Thursday, August 28, 2003 5:49 PM > Subject: Re: [SMARTY-DEV] strip problem again > > > > > > tabs _AFTER_ the include are not stripped. > > > Smarty_Compiler.class.php 1.278 has this > > > fixed already. > > Sorry, it isn't. > > > > But the place is right. > > > > $_strip_search = array( > > '%([^\\\\]\?>)\n%', // remove newlines after PHP close tags > > "!{$ldq}/?strip{$rdq}|\s+$|^\s+!m", // remove leading/trailing space > chars > > '%[\r\n]+%m', // remove CRs and newlines > > '%([^\\\\]\?>)%'); // replace newlines after PHP close tags > > $_strip_replace = array( > > '\\1', > > '', > > '', > > '\\1' . "\n"); > > > > First regexp removes newline and fourth places them back. > > If I remember well there already was a trouble with them. > > > > Yes, I find. > > > > http://lists.php.net/article.php?group=php.smarty.dev&article=1216 > > > > http://lists.php.net/article.php?group=php.smarty.dev&article=1217 > > > > http://lists.php.net/article.php?group=php.smarty.dev&article=1218 > > > > Look there again please. > > > > WBR, > > Konstantin A. Pelepelin > > > > -- > > Smarty Development Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > Smarty Development Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.dev (#1833) next »