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

lexing failed because a rule matched an empty string 3.1.30

 
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
mike_w
Smarty Rookie


Joined: 04 Dec 2016
Posts: 5

PostPosted: Sun Dec 04, 2016 5:05 pm    Post subject: lexing failed because a rule matched an empty string 3.1.30 Reply with quote

lexing failed because a rule matched an empty string ...

After upgrade to 3.1.30 on Debian testing some templates failed to compile with the fatal error

Code:
[:error] [pid 1203] [client 127.0.0.1:35140] PHP Fatal error:  Uncaught Exception: Error: lexing failed because a rule matched an empty string.  Input "0}\n
... state TAGBODY in /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php:566\nStack trace:\n#0
/usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php(263): Smarty_Internal_Templatelexer->yylex3()\n#1
/usr/share/php/smarty3/sysplugins/smarty_internal_smartytemplatecompiler.php(109): Smarty_Internal_Templatelexer->yylex()\n#2
/usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(404): Smarty_Internal_SmartyTemplateCompiler->doCompile('<!DOCTYPE html ...', true)\n#3
/usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(335): Smarty_Internal_TemplateCompilerBase->compileTemplateSource(Object(Smarty_Internal_Template), false, NULL)\n#4
/usr/share/php/smarty3/sysplugins/smarty_template_compiled.php(199): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))\n#5
/usr/share/php/smarty3/sysplugins/smarty_template_compiled.php(98) in /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php on line 566

putting some trace in smarty_internal_templatelexer.php function yylex3() points to a problem with template code with a
literal number 0 on the rhs of a test within {if}

compiling the site ...
Code:
<?php
require_once('/usr/share/php/smarty3/Smarty.class.php');
$smarty=new Smarty();
$smarty->template_dir="/home/www/test/template";
$smarty->compile_dir="/home/www/test/compile";
$smarty->assign('foo',0);
$smarty->assign('data','Hello World');
$smarty->display('index.tpl');
?>


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>               
    <title>test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  </head>
  <body>
    <h1>PHP/Smarty Test</h1>
    {if $foo==0}
      <p>{$data}</p>
    {/if}
  </body>
</html>   

...consistently fails

if $foo==0 is replaced by a literal other than 0 e.g. $foo==1 then compiling passes
$foo==42-42 works
not assigning a value to $foo makes no difference.
Once a template is compiled successfully with a value other than 0, changing back to literal 0 fails on first pass only.


Debian 4.8.7-1 (2016-11-13) x86_64 GNU/Linux
apache2 2.4.23-8
libapache2-mod-php7.0 7.0.13-2
smarty3 3.1.30-1
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Dec 04, 2016 6:07 pm    Post subject: Reply with quote

Unable to reproduce.
Code:
<?php

require_once 'smarty-config.php';

$smarty->assign('foo', 0);
$smarty->assign('data', 1);
$smarty->display(__FILE__);

__HALT_COMPILER();
?>
  {if $foo==0}
    <p>{$data}</p>
  {/if}
  {$smarty.version}

Code:

      <p>1</p>
    3.1.30


Code:
PHP 7.0.13 (cli) (built: Nov  8 2016 13:33:54) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.0rc1, Copyright (c) 2002-2016, by Derick Rethans
Back to top
View user's profile Send private message
mike_w
Smarty Rookie


Joined: 04 Dec 2016
Posts: 5

PostPosted: Sun Dec 04, 2016 11:02 pm    Post subject: Reply with quote

Hmmm...
Using CLI and example code presuming content of smarty-config.php
Code:
<?php
//require_once 'smarty-config.php';
require_once('/usr/share/php/smarty3/Smarty.class.php');
$smarty=new Smarty();
$smarty->setTemplateDir('/home/www/test/template');
$smarty->setCompileDir('/home/www/test/compile');

$smarty->assign('foo', 0);
$smarty->assign('data', 1);
$smarty->display(__FILE__);

__HALT_COMPILER();
?>
  {if $foo==0}
    <p>{$data}</p>
  {/if}
  {$smarty.version}


Code:
PHP Fatal error:  Uncaught Exception: Error: lexing failed because a rule matched an empty string.  Input "0}
  ... state TAGBODY in /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php:566
Stack trace:
#0 /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php(263): Smarty_Internal_Templatelexer->yylex3()
#1 /usr/share/php/smarty3/sysplugins/smarty_internal_smartytemplatecompiler.php(109): Smarty_Internal_Templatelexer->yylex()
#2 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(404): Smarty_Internal_SmartyTemplateCompiler->doCompile('<?php\n\n//requir...', true)
#3 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(335): Smarty_Internal_TemplateCompilerBase->compileTemplateSource(Object(Smarty_Internal_Template), false, NULL)
#4 /usr/share/php/smarty3/sysplugins/smarty_template_compiled.php(199): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#5 /usr/share/php/smarty3/sysplugins/smarty_template_compiled.php(9 in /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php on line 566



Code:
# php -v
PHP 7.0.13-2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13-2, Copyright (c) 1999-2016, by Zend Technologies


Any ideas where to look?
I'll set up a clean minimal install and see what happens.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Dec 05, 2016 3:01 am    Post subject: Reply with quote

mike_w wrote:
presuming content
It's a little more elaborate, than that... but essentially correct.

Now, I'm curious. Tried with web setup proper.
Code:

   {if $foo==0}
PHP version: {$data}
   {/if}
Smarty version: {$smarty.version}

Code:

   PHP version: 7.0.13-1+deb.sury.org~trusty+1
   Smarty version: 3.1.30



Try turning off Zend opcaсhe?
Back to top
View user's profile Send private message
mike_w
Smarty Rookie


Joined: 04 Dec 2016
Posts: 5

PostPosted: Wed Dec 07, 2016 11:46 pm    Post subject: Reply with quote

With a clean install of Debian testing (Virtualbox) running CLI as above

Code:
Linux Test 4.8.0-1-amd64 #1 SMP Debian 4.8.7-1 (2016-11-13) x86_64 GNU/Linux
ii  libapache2-mod-php7.0          7.0.13-2
ii  php-common                     1:46
ii  php7.0                         7.0.13-2
ii  php7.0-cli                     7.0.13-2
ii  php7.0-common                  7.0.13-2
ii  php7.0-json                    7.0.13-2
ii  php7.0-opcache                 7.0.13-2
ii  php7.0-readline                7.0.13-2
ii  smarty3                        3.1.30-1

Code:
PHP Fatal error:  Uncaught Exception: Error: lexing failed because a rule matched an empty string.  Input "0}
  ... state TAGBODY in /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php:566
Stack trace:
#0 /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php(263): Smarty_Internal_Templatelexer->yylex3()
#1 /usr/share/php/smarty3/sysplugins/smarty_internal_smartytemplatecompiler.php(109): Smarty_Internal_Templatelexer->yylex()
#2 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(404): Smarty_Internal_SmartyTemplateCompiler->doCompile('<?php\n//require...', true)
#3 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(335): Smarty_Internal_TemplateCompilerBase->compileTemplateSource(Object(Smarty_Internal_Template), false, NULL)
#4 /usr/share/php/smarty3/sysplugins/smarty_template_compiled.php(199): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#5 /usr/share/php/smarty3/sysplugins/smarty_template_compiled.php(98 in /usr/share/php/smarty3/sysplugins/smarty_internal_templatelexer.php on line 566


opcache?
I have no experience with opcache.

Code:
# php -r "phpinfo();" |grep php.ini
Configuration File (php.ini) Path => /etc/php/7.0/cli
Loaded Configuration File => /etc/php/7.0/cli/php.ini

/etc/php/7.0/cli/php.ini
<snip>
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=0
<snip>


values of 0|1 make no difference to lexing failure
Back to top
View user's profile Send private message
mike_w
Smarty Rookie


Joined: 04 Dec 2016
Posts: 5

PostPosted: Fri Dec 09, 2016 1:35 pm    Post subject: Reply with quote

comparing file 'smarty_internal_templatelexer.php'
extracted from github https://github.com/smarty-php/smarty/archive/v3.1.30.tar.gz
extracted from debian testing http://http.debian.net/debian/pool/main/s/smarty3/smarty3_3.1.30.orig.tar.gz
Files are identical

extracted from github and either package installed or
extracted from /var/cache/apt/archives/smarty3_3.1.30-1_all.deb
Files differ

After substituting function yylex3 in installed file with that from github:
Code:
<?php
//require_once 'smarty-config.php';
require_once '/usr/share/php/smarty3/Smarty.class.php';
$smarty=new Smarty();
$smarty->setTemplateDir('/home/www/test/template');
$smarty->setCompileDir('/home/www/test/compile');

$smarty->assign('foo', 0);
$smarty->assign('data', 1);
$smarty->display(__FILE__);

__HALT_COMPILER();
?>      <p>1</p>
    3.1.30
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Dec 10, 2016 3:10 am    Post subject: Reply with quote

Wait, you mean all this time you've been running a modified version of Smarty?
Back to top
View user's profile Send private message
mike_w
Smarty Rookie


Joined: 04 Dec 2016
Posts: 5

PostPosted: Sat Dec 10, 2016 10:15 am    Post subject: Reply with quote

No.
Standard Debian testing package,
but that package seems to introduce an anomaly which
can be corrected by applying code from its own declared source.
I've raised a bug against the package.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Dec 10, 2016 10:29 pm    Post subject: Reply with quote

mike_w wrote:
No.

"No, I did not run a modified version, it just differs from released code, but it isn't modified, no..."
If a code installed by your package differs from code released via normal Smarty channel (AKA github), then you DID run a modified version of Smarty.
Quote:
I've raised a bug against the package.
Thanks.
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