Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

CVS: Bug in simple math and modifiers

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Mon Sep 29, 2003 11:15 am    Post subject: CVS: Bug in simple math and modifiers Reply with quote

There's a small bug in simple (inline) math of Smarty CVS using in combination with modifiers:

Main App
[php:1:2aad8960d3]<?php
$smarty = new Smarty();
$smarty->assign("foo", 12345678);
$smarty->display("templates/test.tpl");
?>
[/php:1:2aad8960d3]
Template
Code:
{ldelim}$foo{rdelim}                        = {$foo}<br/>
{ldelim}$foo/1000{rdelim}                   = {$foo/1000}<br/>
{ldelim}$foo/1000|number_format:2{rdelim}   = {$foo/1000|number_format:2}<br/>

Output
Code:
{$foo} = 12345678
{$foo/1000} = 12345.678
{$foo/1000|number_format:2} = 12345678


It seems the modifier-regex doesn't cover simple math operations. My outputted template file looks like this:
[php:1:2aad8960d3]<?php /* Smarty version 2.6.0-RC1-cvs, created on 2003-09-29 13:27:08
compiled from templates/test.tpl */ ?>
<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'number_format', 'templates/test.tpl', 3, false),)), $this); ?>
{$foo} = <?php echo $this->_tpl_vars['foo']; ?>
<br/>
{$foo/1000} = <?php echo $this->_tpl_vars['foo']/1000; ?>
<br/>
{$foo/1000|number_format:2} = <?php echo $this->_tpl_vars['foo']/((is_array($_tmp=1000)) ? $this->_run_mod_handler('number_format', true, $_tmp, 2) : smarty_modifier_number_format($_tmp, 2)); ?>
<br/>
[/php:1:2aad8960d3]
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Sep 29, 2003 2:08 pm    Post subject: Reply with quote

yummy, that's a nice one.

actually this
Code:
{$foo ( /1000|number_format:2 )}

is what the compiler sees, but you expect this
Code:
{ ( $foo/1000 ) |number_format:2}

to be compiled.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Mon Sep 29, 2003 4:01 pm    Post subject: Reply with quote

a fix for this issue is in the works...
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Oct 11, 2003 10:02 am    Post subject: Reply with quote

i committed a fix supplied by dominik.

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    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