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

Compiling invalid arithmetic expressions and assuming a $

 
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
gokusandwich
Smarty n00b


Joined: 24 May 2004
Posts: 3

PostPosted: Fri Jun 02, 2006 5:31 pm    Post subject: Compiling invalid arithmetic expressions and assuming a $ Reply with quote

I've created a plug-in, called formSubmitLink. I attempted to invoke the plug-in like so:
Code:

  {formSubmitLink action=$pathToSubmitFormTo
    name="my_link" value=1
    icon=$EASYWEAZE_PREFIX_TO_ADMIN_DIR/images/some-icon.png}
      a link{/formSubmitLink}


I made a mistake, though: I forgot to place quotes around the value for the icon attribute.

Now, obviously Smarty can't know that I intended to put quotes around that expression and that it's actually suppose to be a file path and not an arithmetic expression. However, I think Smarty may have done two things "wrong", when compiling this template:

1) Smarty should have realized that this is not a valid arithmetic expression; it should realize I'm trying to divide by a string value -- "images" in the first case. (Or, would that expression make sense in Smarty code? In PHP code, I don't believe that would make any sense. PHP would probably claim that "images" is an undefined constant and then claim that you cannot divide by a string.)

2) Consider a portion of the output produced when Smarty compiles that above Smarty-code snippet:
[php:1:d76bbc053a]
$this->_tag_stack[] = array(
'formSubmitLink',
array(
'action' => $this->_tpl_vars['pathToSubmitFormTo'],
'name' => 'my_link',
'value' => 1,
'icon' => $this->_tpl_vars['EASYWEAZE_PREFIX_TO_ADMIN_DIR']/$this->_tpl_vars['mages']/$this->_tpl_vars['ome']-$this->_tpl_vars['con']['png']));
[/php:1:d76bbc053a]
What it looks like, is, Smarty assumes that the first character after a division symbol ( / ), is a $ sign. As you can see, it tries to divide by a template variable $mages; it just kind-of ignores the letter i of images.

The error that I ended up seeing, by the time this problem reared its head, was a PHP-produced "Division by zero" error (because the template variable mages was empty), which made the source of the issue a little bit difficult to locate.

This is a bit of a tricky situation, and I'm not entirely sure how Smarty should be expected to react. This issue may require a bit of discussion.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Jun 02, 2006 9:54 pm    Post subject: Reply with quote

Bug? Lets just say that it is undefined behaviour and that fixing it in a regex-engine like Smarty probably isn't trivial. I appreciate the difficulty you must of went through to track down your error but for such a low frequency issue, it doesn't seem very much worth addressing to me. Of course, that is just my take on it Smile
Back to top
View user's profile Send private message
gokusandwich
Smarty n00b


Joined: 24 May 2004
Posts: 3

PostPosted: Fri Jun 09, 2006 7:37 pm    Post subject: Reply with quote

Actually, I located the problem rather quickly... Perhaps out of luck. I Smile

I would agree that this is not high priority. Perhaps, if I am lacking more important things to do, sometime I will try to see how difficult it would be to fix this problem (or these problems). Might be fun to hack on Smarty...

Thanks anyway. Razz
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