View previous topic :: View next topic |
Author |
Message |
danberlyoung Smarty n00b
Joined: 07 Dec 2005 Posts: 1
|
Posted: Wed Dec 07, 2005 7:38 pm Post subject: {strip} tag bug |
|
|
The {strip} form tag seems to have a bug in it. When a tag has its attributes seperated with new line characters to spread the tag out over several lines, {strip} takes out all white space and mashes the attributes together. For example:
Code: |
<foo attr1="one"
attr2="two"
attr3="three" >
|
... becomes ...
Code: |
<foo attr1="one"attr2="two"attr3="three" >
|
... it should be ...
Code: |
<foo attr1="one" attr2="two" attr3="three" >
|
This is with Smarty 2.6.9 on PHP 4.3.11 on Mac OS X Server. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Dec 07, 2005 9:21 pm Post subject: |
|
|
That is how {strip} behaves. You do not want to put {strip} tags around HTML tags that span several lines. |
|
Back to top |
|
rob.desbois Smarty Rookie
Joined: 25 Jan 2006 Posts: 10
|
Posted: Wed Apr 19, 2006 10:50 am Post subject: |
|
|
This foxed me for a bit too - obviously {strip} also does the same to lines of text running over several lines.
A possible suggested solution would be to take advantage of wordwrap in your editor / IDE however that isn't something I want to do.
My solution was the following: in Smarty_Compiler.php find the line that looks like:
<pre> $text_blocks[$j] = preg_replace('![\t ]*[\r\n]+[\t ]*!', '', $text_blocks[$j]);</pre>
(Note: this is from Smarty 2.6.10, and is line 335 in that version)
in the preg_replace call, modify the second argument from '' to ' ' - that will collapse all trailing whitespace,newline characters, and leading whitespace to a single space character. Result: no concatenated words or attributes. |
|
Back to top |
|
rob.desbois Smarty Rookie
Joined: 25 Jan 2006 Posts: 10
|
Posted: Wed Apr 19, 2006 10:53 am Post subject: |
|
|
Mohrt: what is the reasoning behind {strip} performing the way it does? What is its originally specified purpose / speculated usage.
Given my hack above, granted it reduces the removal of unnecessary whitespace as *all* EOLs result in a single character, but this seems far more useful to me than otherwise - given that HTML often contains long sections of prose that may be split over several lines in source.
Do most people program with word-wrap on? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Apr 19, 2006 4:49 pm Post subject: |
|
|
Actually, I think this is probably fairly good solution. It does have one drawback in that it will break current scripts that rely on all whitespace to be eaten. For example, IE will render <a...><img...> differently than <a...> <img...> (where the second form has the space). |
|
Back to top |
|
rob.desbois Smarty Rookie
Joined: 25 Jan 2006 Posts: 10
|
Posted: Thu Apr 20, 2006 8:30 am Post subject: |
|
|
Hmmm that's a pain in the backside...without making it more complex and collapsing all WS if contained in start/end tags I think it'll gave to stay this way. Out of interest, do you know if:
a) this would work if <a...> and <img...> were separated by a newline instead of a space? I assume not, as different types of WS in HTML should be treated generically, but hey, this is I.E.
b) is this an I.E. bug?
My main purpose for using {strip} is simply so that I can fully indent my HTML source which I find extremely useful for editing -- the strip then removes all that WS, effectively compressing it - and usually to about 40% of size! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Apr 20, 2006 5:29 pm Post subject: |
|
|
rob.desbois wrote: | a) this would work if <a...> and <img...> were separated by a newline instead of a space? I assume not, as different types of WS in HTML should be treated generically, but hey, this is I.E.
b) is this an I.E. bug?
|
a) they are the same
b) I don't know. I suppose the 'official' way is to use a & nbsp; but there is a perverse logic to the way it works. *shrug*
rob.desbois wrote: | My main purpose for using {strip} is simply so that I can fully indent my HTML source which I find extremely useful for editing -- the strip then removes all that WS, effectively compressing it - and usually to about 40% of size! |
Have you tried the strip whitespace output filter? |
|
Back to top |
|
rob.desbois Smarty Rookie
Joined: 25 Jan 2006 Posts: 10
|
Posted: Mon Apr 24, 2006 11:36 am Post subject: |
|
|
Hmmm I hadn't - TBH I haven't looked at Smarty's filtering capabilities.
Am I right in thinking {strip} is performed during compilation? Would there be any benefit in using a prefilter (which I'd use over output filter) to do this? Other than not having to hack Smarty's codebase |
|
Back to top |
|
mistic100 Smarty n00b
Joined: 12 May 2011 Posts: 3
|
Posted: Sat Oct 12, 2013 11:28 am Post subject: |
|
|
if someone needs the same modifications, here the the diff for Smarty 3
Code: | Index: distribution/libs/sysplugins/smarty_internal_templateparser.php
===================================================================
--- distribution/libs/sysplugins/smarty_internal_templateparser.php (revision 4788)
+++ distribution/libs/sysplugins/smarty_internal_templateparser.php (working copy)
@@ -2260,7 +2260,7 @@
#line 225 "smarty_internal_templateparser.y"
function yy_r11(){
if ($this->strip) {
- $this->_retvalue = new _smarty_text($this, preg_replace('![\t ]*[\r\n]+[\t ]*!', '', self::escape_start_tag($this->yystack[$this->yyidx + 0]->minor)));
+ $this->_retvalue = new _smarty_text($this, preg_replace('![\t ]*[\r\n]+[\t ]*!', ' ', self::escape_start_tag($this->yystack[$this->yyidx + 0]->minor)));
} else {
$this->_retvalue = new _smarty_text($this, self::escape_start_tag($this->yystack[$this->yyidx + 0]->minor));
}
@@ -2278,7 +2278,7 @@
#line 243 "smarty_internal_templateparser.y"
function yy_r13(){
if ($this->strip) {
- $this->_retvalue = new _smarty_text($this, preg_replace('![\t ]*[\r\n]+[\t ]*!', '', $this->yystack[$this->yyidx + 0]->minor));
+ $this->_retvalue = new _smarty_text($this, preg_replace('![\t ]*[\r\n]+[\t ]*!', ' ', $this->yystack[$this->yyidx + 0]->minor));
} else {
$this->_retvalue = new _smarty_text($this, $this->yystack[$this->yyidx + 0]->minor);
}
|
|
|
Back to top |
|
|