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

Found a bug in smarty_internal_templatelexer.php

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


Joined: 31 Aug 2012
Posts: 1

PostPosted: Wed Jun 01, 2016 9:46 am    Post subject: Found a bug in smarty_internal_templatelexer.php Reply with quote

Hi there,

first I apologize for my poor english...

hope that someone will read my report.

We work with Smarty for more than 10 years, so we're not expert like Smarty's devs but have a good know about this framework.

We found a bug in smarty_internal_templatelexer.php
When using a specific "$smarty->left_delimiter" and "$smarty->right_delimiter", the templatelexer does not "preg_quote" this two properties correctly.

Solution found in smarty_internal_templatelexer.php
Line 213:
replace "$this->ldel = preg_quote($this->smarty->left_delimiter, '~');"
by "$this->ldel = preg_quote($this->smarty->left_delimiter, '/');"

and line 217:
replace "$this->rdel = preg_quote($this->smarty->right_delimiter, '~');"
by "$this->rdel = preg_quote($this->smarty->right_delimiter, '/');


This bug has been found in goal of generate some RTF and DOCS documents. To his feature, we write Words documents with specific <FUSION>$VARIABLE</FUSION> smarty syntax.

Reproduce the bug:
<?php
$smarty = new Smarty();
$smarty->left_delimiter = '<FUSION>';
$smarty->right_delimiter = '</FUSION>';

$templatecode = '<FUSION>{$smarty.date}</FUSION>{\and more code....}';

$smarty->fetch('string:' . $templatecode);
will display ==> "Result: Unexpected input at line 1 : <"

Smarty Version: 3.1.29
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1404

PostPosted: Wed Jun 01, 2016 4:22 pm    Post subject: Reply with quote

I doubt this is the right fix for the issue.
preg_quote does what it does.
Why Smarty chokes on the result is unrelated to the fix presented.
Back to top
View user's profile Send private message
a.shpota
Smarty n00b


Joined: 03 Jun 2016
Posts: 3

PostPosted: Fri Jun 03, 2016 9:07 am    Post subject: Reply with quote

Hi.
I have the same problem and and think that's enough to fix delimiters from '/' to '~' in regular expressions:

https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatelexer.php#L289

https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatelexer.php#L424

https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatelexer.php#L569

https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatelexer.php#L914

https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatelexer.php#L1003


it works for me.

Thanks.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Sep 15, 2016 5:11 am    Post subject: Reply with quote

This was fixed in 3.1.30
Back to top
View user's profile Send private message
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