Re: [SMARTY-DEV] trimwhitespace outputfilter bug
| From: | messju mohr | Date: | Wed, 12 Mar 2003 16:30:23 +0000 |
| Subject: | Re: [SMARTY-DEV] trimwhitespace outputfilter bug | ||
| References: | 1 2 3 4 5 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-948@lists.php.net to get a copy of this message | ||
it is fixed in CVS now. give it a try.
On Tue, Mar 11, 2003 at 10:12:02PM +0100, messju mohr wrote:
> uh, i mixed up some stuff here. don't use the one above, but be sure
> it will be fixed in 2.5.0.
>
> sorry.
> messju
>
>
> On Tue, Mar 11, 2003 at 12:16:45AM +0100, messju mohr wrote:
> > On Tue, Mar 11, 2003 at 12:11:51AM +0100, messju mohr wrote:
> > > On Mon, Mar 10, 2003 at 04:53:02PM -0600, Steve wrote:
> > > > I'm not doing any "quoting". My assignment is (in pseudo code)
> >
> > okay, a patch against the latest cvs is:
> > RCS file: /repository/smarty/libs/plugins/outputfilter.trimwhitespace.php,v
> > retrieving revision 1.2
> > diff -r1.2 outputfilter.trimwhitespace.php
> > 47c47
> > < $source =
> > preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block,$source,1);
> > ---
> > > $source = str_replace($source,
> > > "!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block);
> > 51c51
> > < $source =
> > preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
> > ---
> > > $source = str_replace($source,
> > > "!@@@SMARTY:TRIM:PRE@@@!",$curr_block);
> > 55c55
> > < $source =
> > preg_replace("!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block,$source,1);
> > ---
> > > $source = str_replace($source,
> > > "!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block);
> >
> >
> > or, if you prefer a full version, use this on:
> >
> > ----
> > <?php
> > /*
> > * Smarty plugin
> > * -------------------------------------------------------------
> > * File: outputfilter.trimwhitespace.php
> > * Type: outputfilter
> > * Name: trimwhitespace
> > * Version: 1.3
> > * Date: Jan 25, 2003
> > * Purpose: trim leading white space and blank lines from
> > * template source after it gets interpreted, cleaning
> > * up code and saving bandwidth. Does not affect
> > * <PRE></PRE> and <SCRIPT></SCRIPT> blocks.
> > * Install: Drop into the plugin directory, call
> > * $smarty->load_filter('output','trimwhitespace');
> > * from application.
> > * Author: Monte Ohrt <monte@ispi.net>
> > * Contribs: Lars Noschinski <lars@usenet.noschinski.de>
> > * -------------------------------------------------------------
> > */
> > function smarty_outputfilter_trimwhitespace($source, &$smarty)
> > {
> > // Pull out the script blocks
> > preg_match_all("!<script[^>]+>.*?</script>!is", $source,
> > $match);
> > $_script_blocks = $match[0];
> > $source = preg_replace("!<script[^>]+>.*?</script>!is",
> > '@@@SMARTY:TRIM:SCRIPT@@@', $source);
> >
> > // Pull out the pre blocks
> > preg_match_all("!<pre>.*?</pre>!is", $source, $match);
> > $_pre_blocks = $match[0];
> > $source = preg_replace("!<pre>.*?</pre>!is",
> > '@@@SMARTY:TRIM:PRE@@@', $source);
> >
> > // Pull out the textarea blocks
> > preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source,
> > $match);
> > $_textarea_blocks = $match[0];
> > $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",
> > '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
> >
> > // remove all leading spaces, tabs and carriage returns NOT
> > // preceeded by a php close tag.
> > $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m',
> > '\1', $source));
> >
> > // replace script blocks
> > foreach($_script_blocks as $curr_block) {
> > $source = str_replace($source,
> > "!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block);
> > }
> > // replace pre blocks
> > foreach($_pre_blocks as $curr_block) {
> > $source = str_replace($source,
> > "!@@@SMARTY:TRIM:PRE@@@!",$curr_block);
> > }
> > // replace textarea blocks
> > foreach($_textarea_blocks as $curr_block) {
> > $source = str_replace($source,
> > "!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block);
> > }
> >
> > return $source;
> > }
> > ?>
> > ----
> >
> >
> > please tell me, if it works better. i hope this will get into 2.5.0 then.
> >
> > have fun
> > messju
> >
> > > > $result = mysql_fetch_array($query);
> > > > $a = new Product;
> > > > $a->description = $result['description'];
> > > >
> > > > $tmpl->assign(array('a' => $a));
> > > > $tmpl->display('index.tpl');
> > > >
> > > > I really don't see how this is a problem with my code. The outputfilter is
> > > > ripping out the $59 if it is in a <textarea>, independent of quoting with
> > > > the above assignment, the $59 dissapears in the text area. If I just put
> > > > the {$a->description} outside of the <textarea> it is displayed as
> > > > expected.
> > > >
> > > > Any help or suggestion? Seems to me the outputfilter should check for
> > > > this..
> > >
> > > yes, sorry. i see the problem is in the outputfilter, not in your assignment.
> > > i will have a fix soon.
> > >
> > > > > The problem here is that the assignment is the result of a database query.
> > > > > The code I sent was just an example to illustrate the problem. How do I
> > > > > handle this when a database query is the source of the data for the
> > > > > assignment?
> > > > >
> > > > > Can this be fixed in the outputfilter?
> > > >
> > > > when the data comes from a database and is read to $var, then you
> > > > would $smarty->assign('var', $var) and everything is fine.
> > > >
> > > > but if you hardcode it into php, then your php-interpreter interpolates
> > > > the $... inside your string, far before it is passed to smarty.
> > > >
> > > > so "$59.95 blah blah" means in the php-sourcecode
> > > > "[contents of variable named 59].95 blah blah"
> > > >
> > > > but this is only so inside the php sourcecode and only if you use "
> > > > not if you use '. if you pass variables to functions, or read strings
> > > > out of a file or a database, no such interpolation is done.
> > > >
> > > > read:
> > > > http://www.php.net/manual/en/language.types.string.php
> > > >
> > > > have fun
> > > > messju
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Monte Ohrt [mailto:monte@ispi.net]
> > > > > Sent: Monday, March 10, 2003 8:47 AM
> > > > > To: Steve
> > > > > Cc: Smarty Dev
> > > > > Subject: Re: [SMARTY-DEV] trimwhitespace outputfilter bug
> > > > >
> > > > >
> > > > > $ signs are interperted in double quotes when you assign it. Try one of
> > > > > these:
> > > > >
> > > > > $var = '$59.95 blah blah';
> > > > > $var = "\$59.95 blah blah";
> > > > >
> > > > >
> > > > > On Sat, 2003-03-08 at 22:18, Steve wrote:
> > > > > > this is a good one:)
> > > > > >
> > > > > > pseudo code/explanation:
> > > > > > .php file:
> > > > > > $var = "$59.95 blah blah"
> > > > > > $tmpl->load_filter('output', 'trimwhitespace');
> > > > > >
> > > > > > in template:
> > > > > > {$var}<br>
> > > > > > <textarea>{$var}</textarea>
> > > > > >
> > > > > > output:
> > > > > > $59.95 blah blah<br>
> > > > > > <textarea>.95 blah blah</textarea>
> > > > > >
> > > > > > I looked at the regex, I'm lost. It's ripping away the $59.
> > > > > > Can
> > > > someone
> > > > > > fix this? The filter is great, but not when it breaks the content :)
> > > > > >
> > > > > > Thanks so much,
> > > > > >
> > > > > > Steve
> > > > > --
> > > > > Monte Ohrt <monte@ispi.net>
> > > > >
> > > > >
> > > > > --
> > > > > 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
> > > >
> > > > --
> > > > It is essential that implementations by different vendors interoperate.:
> > > > Unsere proprietären Basteleien dokumentieren wir gar nicht erst.
> > > > Sven
> > > > Türpe
> > > >
> > > > --
> > > > 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
> > >
> > > --
> > > It is essential that implementations by different vendors interoperate.:
> > > Unsere proprietären Basteleien dokumentieren wir gar nicht erst.
> > > Sven Türpe
> > >
> > > --
> > > Smarty Development Mailing List (http://smarty.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > It is essential that implementations by different vendors interoperate.:
> > Unsere proprietären Basteleien dokumentieren wir gar nicht erst.
> > Sven Türpe
>
> --
> GIGA: Der WDR-Computerclub in Farbe.
> Kai Fett
--
c't: Eine weniger gelesene Zeitschrift.
OLG Düsseldorf: AZ 20 U 78/98