Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{strip} bug?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Sun Oct 22, 2017 4:09 pm    Post subject: {strip} bug? Reply with quote

Hi there!

From what i read in the docs (the extra spaces are stripped), I would expect {strip} to "compress" spaces, but always keep at least one.

In fact, it looks like it just strips all spaces indiscriminately.

Let's consider this example:
Code:

   {strip}<input
        type="text"
        name="1234"
    >{/strip}


The output will be:
Code:

<inputtype="text"name="1234">


It would be nice if it kept just one space when multiple spaces are found, so the output would be
Code:

<input type="text" name="1234">


If this is the intended behavior, then maybe add an option "keepone" or "one" to trigger this behavior instead and/or remove the "extra" word from the docs?
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Oct 23, 2017 12:04 am    Post subject: Reply with quote

That is certainly what the docs imply: removes all whitespace from the beginning and end of physical lines.

I guess it is what you define as 'extra'. The example makes it clear to me.

You might try:
Code:
{textformat wrap=8000}<input
        type="text"
        name="1234"
    >{/textformat}
Back to top
View user's profile Send private message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Mon Oct 23, 2017 12:33 am    Post subject: Reply with quote

Thank you, that's a good workaround.
Back to top
View user's profile Send private message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Mon Oct 23, 2017 5:58 am    Post subject: Reply with quote

I correct myself: that does not work, because it also truncates text inside quotes indiscriminately.
Back to top
View user's profile Send private message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Mon Oct 23, 2017 6:21 am    Post subject: Reply with quote

I am now using this

Code:

   /**
    * Smarty plugin
    *
    * Leaves only one space where multiple spaces are found
    */
   public static function mStrip($params, $content, $smarty, &$repeat) {
      if ( ! isset($content) )
         return;

      $out = preg_replace('/\s+/m', ' ', $content);
      if ( $out === null )
         throw new \Exception('Error in estrip block');

      return $out;
   }

        $this->_smarty->registerPlugin('block', 'estrip', ['Page','mStrip']);
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Oct 23, 2017 3:05 pm    Post subject: Reply with quote

Truncates text?

Can you give an example? The example in the docs suggests that nothing but spaces and newlines are lost.

I can see where lines could be split at the exact length limit (your sample suggests final line lengths much shorter than 8000 characters).

I have not looked to see if there is a limit, or if zero would cause a line to never be broken.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Oct 24, 2017 2:25 am    Post subject: Reply with quote

I have a question: why do you think a generic text transformation would correctly apply to a formatted text?
It is more than likely it would break the formatting. Which you, evidently, proved yourself.
If you want to compress the XML, use XML tools.
Back to top
View user's profile Send private message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Fri Oct 27, 2017 11:49 am    Post subject: Reply with quote

bsmither wrote:

Can you give an example? The example in the docs suggests that nothing but spaces and newlines are lost.


That's right, but it does not account for HTML, so an output like

Code:

<input
        type="text"
        name="1234"
        data-comment="this
        is a comment"
    >


does not break textformat specifications, but makes it unsuitable for formatting HTML tags.

Quote:

I have not looked to see if there is a limit, or if zero would cause a line to never be broken.


That is what i would expect too, but actually zero causes every word to be placed on a new line. That is nice too. Having the support for a "-1" argument meaning "infinite" would be even nicer.
Back to top
View user's profile Send private message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Fri Oct 27, 2017 11:51 am    Post subject: Reply with quote

AnrDaemon wrote:
I have a question: why do you think a generic text transformation would correctly apply to a formatted text?
It is more than likely it would break the formatting. Which you, evidently, proved yourself.
If you want to compress the XML, use XML tools.


I had assumed that Smarty was designed to work with HTML. Sorry, my bad.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Oct 27, 2017 12:14 pm    Post subject: Reply with quote

Smarty does not "work with" anything at all.
It only "produces". Output. The format of that output is entirely up to you.

P.S.
What strip does is
Code:
    return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Nov 12, 2017 12:16 am    Post subject: Reply with quote

The behaviour of {strip} has been changed since version 3.1.28 to keep multiline html tags intact.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP