Re: Numeric modifier parameters

messju mohr <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
On Thu, Feb 26, 2004 at 05:12:26PM -0000, Mark Rogers wrote:
> I just created a simple modifier "scale_number" which I use thus:
>     {$data|scale_number:4:-10:20:50}
> 
> The idea was to scale a value between 4 and 20 to one between -10 and 50.
> 
> In doing so I discover that this fools Smarty (2.6.0) because of the - sign.
> I suspect it is being seen as a calculation:
>     ($data|scale_number:4:) - (10:20:50)
> 
> Is this behaviour correct/desirable? I got a bit lost trying to see how it
> would be fixed - guess I don't know the compiler well enough.
> 
> It is possible to work around this with
>     {$data|scale_number:4:"-10":20:50}
> .. but this is not intuitive.

Hmm, I cannot reproduce that, It works fine for me with 2.6.0 and
latest (2.6.2).
 
> Note that "." also fools Smarty in a similar way:
>     {$data|scale_number:4:10.5:20:50}

But i can reproduce that. I propose the following fix for it:

Index: Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.315
diff -u -r1.315 Smarty_Compiler.class.php
--- Smarty_Compiler.class.php   23 Feb 2004 23:14:40 -0000      1.315
+++ Smarty_Compiler.class.php   29 Feb 2004 11:20:25 -0000
@@ -157,7 +157,7 @@
         // |foo:"bar":$foobar
         // |foo|bar
         // |foo:$foo->bar
-        $this->_mod_regexp = '(?:\|@?\w+(?::(?>-?\w+|'
+        $this->_mod_regexp = '(?:\|@?\w+(?::(?>-?\d+(?:\.\d+)?|\w+|'
            . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)';
 
         // matches valid function name:


If nobody sees a problem with this change, I'll commit it.

Greetings
messju

> -- 
> Mark Rogers,
> More Solutions Ltd

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.