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

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


Joined: 21 Dec 2011
Posts: 10

PostPosted: Wed Dec 21, 2011 10:33 am    Post subject: 3.1.7 - template compilation error Reply with quote

Hi,
I found an issue when compiling a template with the following conditions:
* mbstring.func_overload = 2 (string functions are replaced by the mbstring ones)
* Template is inherited
* Non-latin unicode characters are used
* A static function call is written in a template

Here is the code:

index.php:

Code:
<?
require_once('Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->display('test.tpl');

class Test{
    static function foo($param1,$param2){}
}


test.tpl:
Code:
{extends file='parent.tpl'}
{block content}
русский текст (any russian text in UTF-8, this forum uses cp1251, blind copy-paste may not work)
    {Test::link(1,2)}
{/block}


parent.tpl:
Code:
{block content}{/block}


The error is due to the timeout:
Quote:
Fatal error: Maximum execution time of 30 seconds exceeded in /www/test/Smarty/sysplugins/smarty_internal_templateparser.php on line 1764

exact line numbers may differ.

If I remove either the static call or non-latin text from the template, it compiles in 0.4 sec.


In 3.1.6 and before usage of UTF8 with inheritance and mbstring.func_overload caused an error like:
Quote:

SmartyCompilerException
Syntax Error in template "...views/site/test.tpl" on line 19 "{/block}" unexpected closing tag

Now it just hangs up during compilation when you use static calls.

WBR, Grigori
Back to top
View user's profile Send private message
Grigori
Smarty Rookie


Joined: 21 Dec 2011
Posts: 10

PostPosted: Wed Dec 21, 2011 7:51 pm    Post subject: Reply with quote

We can reproduce this issue on linux with PHP 5.3.6 and FreeBsd with 5.2.17, MacOS with PHP 5.4 RC3

But I can't reproduce it on the same freebsd server on 5.3.3 cli though (with the same php.ini)

Maybe just the last PHPs has this issue.

Can someone reproduce it on your systems as well please? Maybe we can find the dependency.

Here is the archive with the code to reproduce:
http://grik.net/smarty_bug.tar.bz2

Just remember to set mbstring.func_overload = 2 when you test Wink
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Dec 21, 2011 9:06 pm    Post subject: Reply with quote

It looks like that this is related to https://bugs.php.net/bug.php?id=27421

If you use mbstring.func_overload the overloading of the strlen function does not work correctly on a couple of PHP versions.

According to the traceback information you provided in the private mail
we have an endless loop at strlen.

Not sure if we can find a workaround for this. mbstring.func_overload is a pain....
Back to top
View user's profile Send private message
Grigori
Smarty Rookie


Joined: 21 Dec 2011
Posts: 10

PostPosted: Wed Dec 21, 2011 10:00 pm    Post subject: Reply with quote

The bug 27421 is not involved (it's fixed). With mbstring.func_overload=2 and mbstring.internal_encoding=UTF-8 the code
Code:
$v = 'русский{Test::foo(1,2)}';
print strlen(substr($v,0,strpos($v,'{')));
gives 7 and is correct.

But Smarty crashes.

We are just writing a system that is meant to be portable, and found the issue on one of our servers.

If you prefer leaving it unfixed, well, it would be nice to mention in the documentation that mbstring.func_overload sholuld not be 2 (or 7).

Thanks, Grigori
Back to top
View user's profile Send private message
Grigori
Smarty Rookie


Joined: 21 Dec 2011
Posts: 10

PostPosted: Thu Dec 22, 2011 8:38 am    Post subject: Reply with quote

Why do you write
Quote:

Not sure if we can find a workaround

?
when you have a workaround already?
You are detecting mbstring.func_overload in smarty_internal_templatelexer.php (line 90)
and branching the logic according to this settings.

Here's the parser debug output:

Quote:

Line 1 Parsing LDEL Token {

Input LDEL
Shift 43
Stack: LDEL
Line 1 Parsing ID Token extends

Input ID
Shift 92
Stack: LDEL ID
Line 1 Parsing SPACE Token

Input SPACE
Shift 42
Stack: LDEL ID SPACE
Line 1 Parsing ID Token file

Input ID
Shift 206
Stack: LDEL ID SPACE ID
Line 1 Parsing EQUAL Token =

Input EQUAL
Shift 27
Stack: LDEL ID SPACE ID EQUAL
Line 1 Parsing SINGLEQUOTESTRING Token 'parent.tpl'

Input SINGLEQUOTESTRING
Shift 363
Stack: LDEL ID SPACE ID EQUAL SINGLEQUOTESTRING
Line 1 Parsing RDEL Token }

Input RDEL
Reduce (116) [value ::= SINGLEQUOTESTRING].
Shift 115
Stack: LDEL ID SPACE ID EQUAL value
Reduce (67) [attribute ::= SPACE ID EQUAL value].
Shift 292
Stack: LDEL ID attribute
Reduce (63) [attributes ::= attribute].
Shift 175
Stack: LDEL ID attributes
Shift 340
Stack: LDEL ID attributes RDEL
Line 2 Parsing TEXT Token

Input TEXT
Reduce (36) [smartytag ::= LDEL ID attributes RDEL].
Shift 318
Stack: smartytag
Reduce (4) [template_element ::= smartytag].
Shift 255
Stack: template_element
Reduce (1) [template ::= template_element].
Shift 95
Stack: template
Shift 314
Stack: template TEXT
Line 1 Parsing LDEL Token {

Input LDEL
Shift 43
Stack: LDEL
Line 1 Parsing ID Token block

Input ID
Shift 92
Stack: LDEL ID
Line 1 Parsing SPACE Token

Input SPACE
Shift 42
Stack: LDEL ID SPACE
Line 1 Parsing ID Token content

Input ID
Shift 206
Stack: LDEL ID SPACE ID
Line 1 Parsing RDEL Token }

Input RDEL
Reduce (68) [attribute ::= SPACE ID].
Shift 292
Stack: LDEL ID attribute
Reduce (63) [attributes ::= attribute].
Shift 175
Stack: LDEL ID attributes
Shift 340
Stack: LDEL ID attributes RDEL
Line 1 Parsing LDELSLASH Token {/

Input LDELSLASH
Reduce (36) [smartytag ::= LDEL ID attributes RDEL].
Shift 318
Stack: smartytag
Reduce (4) [template_element ::= smartytag].
Shift 255
Stack: template_element
Reduce (1) [template ::= template_element].
Shift 95
Stack: template
Shift 241
Stack: template LDELSLASH
Line 1 Parsing ID Token block

Input ID
Shift 121
Stack: template LDELSLASH ID
Line 1 Parsing RDEL Token }

Input RDEL
Shift 296
Stack: template LDELSLASH ID RDEL
Line 2 Parsing TEXT Token

Input TEXT
Reduce (58) [smartytag ::= LDELSLASH ID RDEL].
Line 3 Parsing TEXT Token
ЂѓЃЃкий текЃт
{Test::foo(1

Input TEXT
Shift 314
Stack: TEXT
Line 3 Parsing TEXT Token

Input TEXT
Reduce (13) [template_element ::= TEXT].
Shift 255
Stack: template_element
Reduce (1) [template ::= template_element].
Shift 95
Stack: template
Shift 314
Stack: template TEXT
Line 3 Parsing TEXT Token

Input TEXT
Reduce (13) [template_element ::= TEXT].
Shift 317
Stack: template template_element
Reduce (2) [template ::= template template_element].
Shift 95
Stack: template
Shift 314
Stack: template TEXT
Line 3 Parsing TEXT Token

Input TEXT
Reduce (13) [template_element ::= TEXT].
Shift 317
Stack: template template_element
Reduce (2) [template ::= template template_element].
Shift 95
Stack: template
Shift 314
Stack: template TEXT
Line 3 Parsing TEXT Token

Input TEXT
Reduce (13) [template_element ::= TEXT].
Shift 317
Stack: template template_element
Reduce (2) [template ::= template template_element].
Shift 95
Stack: template
Shift 314
Stack: template TEXT

... endless repeat
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Thu Dec 22, 2011 1:51 pm    Post subject: Reply with quote

Please keep your pants on. Anyone using func_overload (for whatever register_globals-ish reasons) please revert back to 3.1.6 for the time being.

-> http://code.google.com/p/smarty-php/issues/detail?id=70
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Thu Dec 22, 2011 4:35 pm    Post subject: Reply with quote

This is fixed in the SVN trunk version and will be included in 3.1.8.

Please confirm if this is working at your place
Back to top
View user's profile Send private message
Grigori
Smarty Rookie


Joined: 21 Dec 2011
Posts: 10

PostPosted: Thu Dec 22, 2011 6:08 pm    Post subject: Reply with quote

rodneyrehm wrote:
Please keep your pants on. Anyone using func_overload (for whatever register_globals-ish reasons) please revert back to 3.1.6 for the time being.

-> http://code.google.com/p/smarty-php/issues/detail?id=70


In the 3.1.6 it triggers an error.

I mentioned it in the bug report:
Quote:

In 3.1.6 and before usage of UTF8 with inheritance and mbstring.func_overload caused an error like:
Quote:

SmartyCompilerException
Syntax Error in template "...views/site/test.tpl" on line 19 "{/block}" unexpected closing tag

Checking the trunk.
Back to top
View user's profile Send private message
Grigori
Smarty Rookie


Joined: 21 Dec 2011
Posts: 10

PostPosted: Thu Dec 22, 2011 6:23 pm    Post subject: Reply with quote

U.Tews wrote:
This is fixed in the SVN trunk version and will be included in 3.1.8.

Please confirm if this is working at your place


It gives a template error:

Quote:


$ php -d mbstring.func_overload=7 -d mbstring.internal_encoding =UTF-8 index.php
...
SmartyCompilerException: Syntax Error in template "test.tpl" on line 4 "{/block}" unexpected closing tag in /www/test/trunk/sysplugins/smarty_internal_template compilerbase.php on line 621

Call Stack:
0.0034 327104 1. {main}() /www/test/index.php:0
0.0709 1557320 2. Smarty_Internal_TemplateBase->display(string(Cool, ???,???, ???) /www/test/index.php:8
0.0709 1557576 3. Smarty_Internal_TemplateBase->fetch(string(Cool, null, null, null, bool, ???, ???) /www/test/trunk/sysplugins/smarty_internal_templatebase.php:374
0.0775 1569552 4. Smarty_Internal_Template->compileTemplateSource() /www/test/trunk/sysplugins/smarty_internal_templatebase.php:155


Without mbstring.func_overload it works fine:
Quote:
$ php index.php
я─я┐я│я│п╨п╦п╧ я┌п╣п╨я│я┌
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Dec 22, 2011 7:39 pm    Post subject: Reply with quote

Grigori

Sorry, I missed annother location.

The trunk is updated once again.

Can you retry?
Back to top
View user's profile Send private message
Grigori
Smarty Rookie


Joined: 21 Dec 2011
Posts: 10

PostPosted: Thu Dec 22, 2011 8:33 pm    Post subject: Reply with quote

U.Tews wrote:
Grigori

Sorry, I missed annother location.

The trunk is updated once again.

Can you retry?

Wow! Looks working now on my local server. I will test on other servers as well, if it comes out it fails I will write, but I assume it's fixed. Thanks!
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