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

PHP_ALLOW failing on... bkslash-newlines and double quotes?

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


Joined: 27 Feb 2017
Posts: 1

PostPosted: Mon Feb 27, 2017 11:49 pm    Post subject: PHP_ALLOW failing on... bkslash-newlines and double quotes? Reply with quote

In Smarty 3.1.11 (the last I had before upgrading), this template worked like a charm:

Code:

<?
$bad_template = '<? echo "\n"; ?> "foo1"';  // perfectly valid PHP code, stored in a string. Would print a newline, and then "foo1" in double quotes.
$good_template1 = '<? echo chr(13); ?> "foo2"';  // chr(13) instead of a backslashed newline.
$good_template2 = '<? echo "\n"; ?> foo3';  // removed the double quotes.

require_once($_SERVER['DOCUMENT_ROOT'].'/includes/smarty-3.1.30/libs/SmartyBC.class.php');
$t = new SmartyBC();
$t->force_compile = 1;


$t->display('string:'.$good_template1); // works fine.
echo "- OK<br>";

$t->display('string:'.$good_template2); // works fine.
echo "- OK<br>";

$t->display('string:'.$bad_template); // works fine.
echo "- OK<br>";

echo "Enabling php_handling...<br>";

$t->php_handling = Smarty::PHP_ALLOW;

$t->display('string:'.$good_template1); // works fine.
echo "- OK<br>";
$t->display('string:'.$good_template2); // works fine.
echo "- OK<br>";
try {
    $t->display('string:'.$bad_template);
} catch (SmartyCompilerException $e) {
    echo "No go! Bad template! <pre>".htmlspecialchars($e->getMessage())."</pre>";
}
?>


In Smarty 3.1.30, setting php_handling to PHP_ALLOW (I know, bad idea, but that's irrelevant) causes some templates to fail to compile. In this example, the presence of \n and a double-quoted word at the same time triggers the failure. Removing the quotes, or the \n, works around the problem. You could substitute the \n with a plain double backslash, for even weirder results.
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