From 550702fc0a85a690cd96ad44059bc6e13e5383ee Mon Sep 17 00:00:00 2001 From: artcs Date: Tue, 14 Apr 2020 22:03:25 +0200 Subject: [PATCH 1/5] add $allow_inline_constants --- libs/Smarty.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 44589328e..4e3b12226 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.36'; + const SMARTY_VERSION = '3.1.37-dev-1'; /** * define variable scopes */ @@ -310,6 +310,14 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $allow_ambiguous_resources = false; + /** + * allow inline constants (use defined constants without the $smarty.const. prefix) + * default to true for backwards compatibility + * + * @var boolean + */ + public $allow_inline_constants = true; + /** * merge compiled includes * From dd309a7777ca2f766368f66ed17f3972c70ef630 Mon Sep 17 00:00:00 2001 From: artcs Date: Tue, 14 Apr 2020 22:04:35 +0200 Subject: [PATCH 2/5] use $allow_inline_constants --- lexer/smarty_internal_templateparser.y | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lexer/smarty_internal_templateparser.y b/lexer/smarty_internal_templateparser.y index b8c00e5d9..6b4cb8a3f 100644 --- a/lexer/smarty_internal_templateparser.y +++ b/lexer/smarty_internal_templateparser.y @@ -154,6 +154,7 @@ class Smarty_Internal_Templateparser $this->template = $this->compiler->template; $this->smarty = $this->template->smarty; $this->security = isset($this->smarty->security_policy) ? $this->smarty->security_policy : false; + $this->allow_inline_constants = $this->smarty->allow_inline_constants; $this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template(); } @@ -310,7 +311,7 @@ smartytag(A)::= SIMPLETAG(B). { $this->strip = true; A = null;; } else { - if (defined($tag)) { + if ($this->allow_inline_constants AND defined($tag)) { if ($this->security) { $this->security->isTrustedConstant($tag, $this->compiler); } @@ -381,7 +382,7 @@ output(A) ::= expr(B). { // tag with optional Smarty2 style attributes tag(res) ::= LDEL ID(i) attributes(a). { - if (defined(i)) { + if ($this->allow_inline_constants AND defined(i)) { if ($this->security) { $this->security->isTrustedConstant(i, $this->compiler); } @@ -391,7 +392,7 @@ tag(res) ::= LDEL ID(i) attributes(a). { } } tag(res) ::= LDEL ID(i). { - if (defined(i)) { + if ($this->allow_inline_constants AND defined(i)) { if ($this->security) { $this->security->isTrustedConstant(i, $this->compiler); } @@ -404,7 +405,7 @@ tag(res) ::= LDEL ID(i). { // tag with modifier and optional Smarty2 style attributes tag(res) ::= LDEL ID(i) modifierlist(l)attributes(a). { - if (defined(i)) { + if ($this->allow_inline_constants AND defined(i)) { if ($this->security) { $this->security->isTrustedConstant(i, $this->compiler); } @@ -541,7 +542,7 @@ attributes(res) ::= . { // attribute attribute(res) ::= SPACE ID(v) EQUAL ID(id). { - if (defined(id)) { + if ($this->allow_inline_constants AND defined(id)) { if ($this->security) { $this->security->isTrustedConstant(id, $this->compiler); } @@ -713,7 +714,7 @@ value(res) ::= DOT INTEGER(n1). { // ID, true, false, null value(res) ::= ID(id). { - if (defined(id)) { + if ($this->allow_inline_constants AND defined(id)) { if ($this->security) { $this->security->isTrustedConstant(id, $this->compiler); } From b8f16364b3cda87ddd329192e5d94bfa64dc65ad Mon Sep 17 00:00:00 2001 From: artcs Date: Tue, 14 Apr 2020 22:05:42 +0200 Subject: [PATCH 3/5] use $allow_inline_constants --- libs/sysplugins/smarty_internal_templateparser.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index aaeae63b7..3b04d25fa 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -1771,6 +1771,7 @@ public function __construct(Smarty_Internal_Templatelexer $lex, Smarty_Internal_ $this->template = $this->compiler->template; $this->smarty = $this->template->smarty; $this->security = isset($this->smarty->security_policy) ? $this->smarty->security_policy : false; + $this->allow_inline_constants = $this->smarty->allow_inline_constants; $this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template(); } /* The parser's stack */ public static function yy_destructor($yymajor, $yypminor) @@ -2259,7 +2260,7 @@ public function yy_r13() $this->strip = true; $this->_retvalue = null; } else { - if (defined($tag)) { + if ($this->allow_inline_constants AND defined($tag)) { if ($this->security) { $this->security->isTrustedConstant($tag, $this->compiler); } @@ -2348,7 +2349,7 @@ public function yy_r21() // line 393 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r25() { - if (defined($this->yystack[ $this->yyidx + -1 ]->minor)) { + if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + -1 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + -1 ]->minor, $this->compiler); } @@ -2365,7 +2366,7 @@ public function yy_r25() // line 406 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r26() { - if (defined($this->yystack[ $this->yyidx + 0 ]->minor)) { + if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + 0 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + 0 ]->minor, $this->compiler); } @@ -2380,7 +2381,7 @@ public function yy_r26() // line 418 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r27() { - if (defined($this->yystack[ $this->yyidx + -2 ]->minor)) { + if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + -2 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + -2 ]->minor, $this->compiler); } @@ -2614,7 +2615,7 @@ public function yy_r52() // line 554 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r53() { - if (defined($this->yystack[ $this->yyidx + 0 ]->minor)) { + if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + 0 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + 0 ]->minor, $this->compiler); } @@ -2809,7 +2810,7 @@ public function yy_r87() // line 732 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r88() { - if (defined($this->yystack[ $this->yyidx + 0 ]->minor)) { + if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + 0 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + 0 ]->minor, $this->compiler); } From 8ecd215241143b0ed7d55e361c170fe8a3554b28 Mon Sep 17 00:00:00 2001 From: artcs Date: Sun, 10 May 2020 19:28:50 +0200 Subject: [PATCH 4/5] fix function calls --- lexer/smarty_internal_templateparser.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lexer/smarty_internal_templateparser.y b/lexer/smarty_internal_templateparser.y index 6b4cb8a3f..db3317fe5 100644 --- a/lexer/smarty_internal_templateparser.y +++ b/lexer/smarty_internal_templateparser.y @@ -542,7 +542,7 @@ attributes(res) ::= . { // attribute attribute(res) ::= SPACE ID(v) EQUAL ID(id). { - if ($this->allow_inline_constants AND defined(id)) { + if (defined(id)) { if ($this->security) { $this->security->isTrustedConstant(id, $this->compiler); } @@ -714,7 +714,7 @@ value(res) ::= DOT INTEGER(n1). { // ID, true, false, null value(res) ::= ID(id). { - if ($this->allow_inline_constants AND defined(id)) { + if (defined(id)) { if ($this->security) { $this->security->isTrustedConstant(id, $this->compiler); } From db044a1b94cf3b82a95473dc994cb817b1eafe75 Mon Sep 17 00:00:00 2001 From: artcs Date: Sun, 10 May 2020 19:29:39 +0200 Subject: [PATCH 5/5] fix function calls --- libs/sysplugins/smarty_internal_templateparser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index 3b04d25fa..2813c4d87 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -2615,7 +2615,7 @@ public function yy_r52() // line 554 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r53() { - if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + 0 ]->minor)) { + if (defined($this->yystack[ $this->yyidx + 0 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + 0 ]->minor, $this->compiler); } @@ -2810,7 +2810,7 @@ public function yy_r87() // line 732 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r88() { - if ($this->allow_inline_constants AND defined($this->yystack[ $this->yyidx + 0 ]->minor)) { + if (defined($this->yystack[ $this->yyidx + 0 ]->minor)) { if ($this->security) { $this->security->isTrustedConstant($this->yystack[ $this->yyidx + 0 ]->minor, $this->compiler); }