mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- bugfix wrong precedence on special if conditions like '$foo is ... by $bar' could cause wrong code https://github.com/smarty-php/smarty/issues/178
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||
10.02.2016
|
||||
- bugfix {strip} must keep space on output creating smarty tags within html tags https://github.com/smarty-php/smarty/issues/177
|
||||
- bugfix wrong precedence on special if conditions like '$foo is ... by $bar' could cause wrong code https://github.com/smarty-php/smarty/issues/178
|
||||
|
||||
09.02.2016
|
||||
- move some code from parser into compiler
|
||||
|
@@ -306,7 +306,8 @@ class Smarty_Internal_Templatelexer
|
||||
literal = ~literal~
|
||||
strip = ~strip~
|
||||
lop = ~\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\s*~
|
||||
tlop = ~\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor|(is\s+(not\s+)?(odd|even|div)\s+by))\s+~
|
||||
slop = ~\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\s+~
|
||||
tlop = ~\s+(is\s+(not\s+)?(odd|even|div)\s+by)\s+~
|
||||
scond = ~\s+is\s+(not\s+)?(odd|even)~
|
||||
isin = ~\s+is\s+in\s+~
|
||||
as = ~\s+as\s+~
|
||||
@@ -479,6 +480,9 @@ class Smarty_Internal_Templatelexer
|
||||
lop {
|
||||
$this->token = Smarty_Internal_Templateparser::TP_LOGOP;
|
||||
}
|
||||
slop {
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SLOGOP;
|
||||
}
|
||||
tlop {
|
||||
$this->token = Smarty_Internal_Templateparser::TP_TLOGOP;
|
||||
}
|
||||
|
@@ -690,10 +690,15 @@ expr(res) ::= expr(e) modifierlist(l). {
|
||||
}
|
||||
|
||||
// if expression
|
||||
// special conditions
|
||||
expr(res) ::= expr(e1) tlop(c) value(e2). {
|
||||
res = c['pre']. e1.c['op'].e2 .')';
|
||||
}
|
||||
// simple expression
|
||||
expr(res) ::= expr(e1) lop(c) expr(e2). {
|
||||
res = (isset(c['pre']) ? c['pre'] : '') . e1.c['op'].e2 . (isset(c['pre']) ? ')' : '');
|
||||
res = e1.c.e2;
|
||||
}
|
||||
|
||||
expr(res) ::= expr(e1) scond(c). {
|
||||
res = c . e1 . ')';
|
||||
}
|
||||
@@ -1222,24 +1227,30 @@ static_class_access(res) ::= DOLLARID(v) arrayindex(a) objectchain(oc). {
|
||||
|
||||
// if conditions and operators
|
||||
lop(res) ::= LOGOP(o). {
|
||||
res['op'] = ' '. trim(o) . ' ';
|
||||
res = ' '. trim(o) . ' ';
|
||||
}
|
||||
|
||||
lop(res) ::= TLOGOP(o). {
|
||||
lop(res) ::= SLOGOP(o). {
|
||||
static $lops = array(
|
||||
'eq' => array('op' => ' == ', 'pre' => null),
|
||||
'ne' => array('op' => ' != ', 'pre' => null),
|
||||
'neq' => array('op' => ' != ', 'pre' => null),
|
||||
'gt' => array('op' => ' > ', 'pre' => null),
|
||||
'ge' => array('op' => ' >= ', 'pre' => null),
|
||||
'gte' => array('op' => ' >= ', 'pre' => null),
|
||||
'lt' => array('op' => ' < ', 'pre' => null),
|
||||
'le' => array('op' => ' <= ', 'pre' => null),
|
||||
'lte' => array('op' => ' <= ', 'pre' => null),
|
||||
'mod' => array('op' => ' % ', 'pre' => null),
|
||||
'and' => array('op' => ' && ', 'pre' => null),
|
||||
'or' => array('op' => ' || ', 'pre' => null),
|
||||
'xor' => array('op' => ' xor ', 'pre' => null),
|
||||
'eq' => ' == ',
|
||||
'ne' => ' != ',
|
||||
'neq' => ' != ',
|
||||
'gt' => ' > ',
|
||||
'ge' => ' >= ',
|
||||
'gte' => ' >= ',
|
||||
'lt' => ' < ',
|
||||
'le' => ' <= ',
|
||||
'lte' => ' <= ',
|
||||
'mod' => ' % ',
|
||||
'and' => ' && ',
|
||||
'or' => ' || ',
|
||||
'xor' => ' xor ',
|
||||
);
|
||||
$op = strtolower(preg_replace('/\s*/', '', o));
|
||||
res = $lops[$op];
|
||||
}
|
||||
tlop(res) ::= TLOGOP(o). {
|
||||
static $tlops = array(
|
||||
'isdivby' => array('op' => ' % ', 'pre' => '!('),
|
||||
'isnotdivby' => array('op' => ' % ', 'pre' => '('),
|
||||
'isevenby' => array('op' => ' / ', 'pre' => '!(1 & '),
|
||||
@@ -1248,8 +1259,8 @@ lop(res) ::= TLOGOP(o). {
|
||||
'isnotoddby' => array('op' => ' / ', 'pre' => '!(1 & '),
|
||||
);
|
||||
$op = strtolower(preg_replace('/\s*/', '', o));
|
||||
res = $lops[$op];
|
||||
}
|
||||
res = $tlops[$op];
|
||||
}
|
||||
|
||||
scond(res) ::= SINGLECOND(o). {
|
||||
static $scond = array (
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/34';
|
||||
const SMARTY_VERSION = '3.1.30-dev/35';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -559,7 +559,7 @@ class Smarty_Internal_Templatelexer
|
||||
{
|
||||
if (!isset($this->yy_global_pattern3)) {
|
||||
$this->yy_global_pattern3 = "/\G(\\s*" . $this->rdel . ")|\G(" . $this->ldel .
|
||||
"\\s*)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor|(is\\s+(not\\s+)?(odd|even|div)\\s+by))\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\s+))|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS";
|
||||
"\\s*)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor)\\s+)|\G(\\s+(is\\s+(not\\s+)?(odd|even|div)\\s+by)\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\s+))|\G([(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\\s*)|\G(\\s*[(]\\s*)|\G(\\s*[)])|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*[-][>]\\s*)|\G(\\s*[=][>]\\s*)|\G(\\s*[=]\\s*)|\G(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS";
|
||||
}
|
||||
if ($this->counter >= strlen($this->data)) {
|
||||
return false; // end of input
|
||||
@@ -698,102 +698,108 @@ class Smarty_Internal_Templatelexer
|
||||
}
|
||||
|
||||
function yy_r3_19()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SLOGOP;
|
||||
}
|
||||
|
||||
function yy_r3_21()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_TLOGOP;
|
||||
}
|
||||
|
||||
function yy_r3_24()
|
||||
function yy_r3_25()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SINGLECOND;
|
||||
}
|
||||
|
||||
function yy_r3_27()
|
||||
function yy_r3_28()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_NOT;
|
||||
}
|
||||
|
||||
function yy_r3_30()
|
||||
function yy_r3_31()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_TYPECAST;
|
||||
}
|
||||
|
||||
function yy_r3_34()
|
||||
function yy_r3_35()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OPENP;
|
||||
}
|
||||
|
||||
function yy_r3_35()
|
||||
function yy_r3_36()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_CLOSEP;
|
||||
}
|
||||
|
||||
function yy_r3_36()
|
||||
function yy_r3_37()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_OPENB;
|
||||
}
|
||||
|
||||
function yy_r3_37()
|
||||
function yy_r3_38()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_CLOSEB;
|
||||
}
|
||||
|
||||
function yy_r3_38()
|
||||
function yy_r3_39()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_PTR;
|
||||
}
|
||||
|
||||
function yy_r3_39()
|
||||
function yy_r3_40()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_APTR;
|
||||
}
|
||||
|
||||
function yy_r3_40()
|
||||
function yy_r3_41()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_EQUAL;
|
||||
}
|
||||
|
||||
function yy_r3_41()
|
||||
function yy_r3_42()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_INCDEC;
|
||||
}
|
||||
|
||||
function yy_r3_43()
|
||||
function yy_r3_44()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_UNIMATH;
|
||||
}
|
||||
|
||||
function yy_r3_45()
|
||||
function yy_r3_46()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_MATH;
|
||||
}
|
||||
|
||||
function yy_r3_47()
|
||||
function yy_r3_48()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_AT;
|
||||
}
|
||||
|
||||
function yy_r3_48()
|
||||
function yy_r3_49()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_HATCH;
|
||||
}
|
||||
|
||||
function yy_r3_49()
|
||||
function yy_r3_50()
|
||||
{
|
||||
|
||||
// resolve conflicts with shorttag and right_delimiter starting with '='
|
||||
@@ -808,86 +814,86 @@ class Smarty_Internal_Templatelexer
|
||||
}
|
||||
}
|
||||
|
||||
function yy_r3_50()
|
||||
function yy_r3_51()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_NAMESPACE;
|
||||
}
|
||||
|
||||
function yy_r3_53()
|
||||
function yy_r3_54()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_ID;
|
||||
}
|
||||
|
||||
function yy_r3_54()
|
||||
function yy_r3_55()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_INTEGER;
|
||||
}
|
||||
|
||||
function yy_r3_55()
|
||||
function yy_r3_56()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
|
||||
$this->yypopstate();
|
||||
}
|
||||
|
||||
function yy_r3_56()
|
||||
function yy_r3_57()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_VERT;
|
||||
}
|
||||
|
||||
function yy_r3_57()
|
||||
function yy_r3_58()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_DOT;
|
||||
}
|
||||
|
||||
function yy_r3_58()
|
||||
function yy_r3_59()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_COMMA;
|
||||
}
|
||||
|
||||
function yy_r3_59()
|
||||
function yy_r3_60()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SEMICOLON;
|
||||
}
|
||||
|
||||
function yy_r3_60()
|
||||
function yy_r3_61()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON;
|
||||
}
|
||||
|
||||
function yy_r3_61()
|
||||
function yy_r3_62()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_COLON;
|
||||
}
|
||||
|
||||
function yy_r3_62()
|
||||
function yy_r3_63()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_QMARK;
|
||||
}
|
||||
|
||||
function yy_r3_63()
|
||||
function yy_r3_64()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_HEX;
|
||||
}
|
||||
|
||||
function yy_r3_64()
|
||||
function yy_r3_65()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
|
||||
}
|
||||
|
||||
function yy_r3_65()
|
||||
function yy_r3_66()
|
||||
{
|
||||
|
||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user