Skip to content

Commit

Permalink
3.1.21 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Dec 15, 2014
1 parent dc45036 commit 84a1cf0
Show file tree
Hide file tree
Showing 4 changed files with 1,986 additions and 2,055 deletions.
123 changes: 42 additions & 81 deletions smarty_internal_templatelexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Smarty_Internal_Templatelexer
public $is_phpScript = false;
public $state = 1;
public $smarty;
public $literal_cnt = 0;
private $heredoc_id_stack = Array();
public $yyTraceFILE;
public $yyTracePrompt;
Expand Down Expand Up @@ -164,12 +165,11 @@ public function yylex1()
20 => 0,
21 => 0,
22 => 0,
23 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G(\\{\\})|\G(" . $this->ldel . "\\*([\S\s]*?)\\*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G((<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|(<\\?(?:php\\w+|=|[a-zA-Z]+)?))|\G(\\?>)|\G(<\/script>)|\G(<\/script>)|\G(\\s*" . $this->rdel . ")|\G(<%)|\G(%>)|\G([\S\s])/iS";
$yy_global_pattern = "/\G(\\{\\})|\G(" . $this->ldel . "\\*([\S\s]*?)\\*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G((<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|(<\\?(?:php\\w+|=|[a-zA-Z]+)?))|\G(\\?>)|\G(<\/script>)|\G(\\s*" . $this->rdel . ")|\G(<%)|\G(%>)|\G([\S\s])/iS";

do {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
Expand Down Expand Up @@ -337,16 +337,16 @@ function yy_r1_13($yy_subpatterns)
function yy_r1_14($yy_subpatterns)
{

if (in_array($this->value, Array('<?', '<?=', '<?php')) || $script = strpos($this->value, '<s') === 0) {
if (($script = strpos($this->value, '<s') === 0) || in_array($this->value, Array('<?', '<?=', '<?php'))) {
if ($script) {
$this->is_phpScript = true;
}
$this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
} elseif ($this->value == '<?xml') {
$this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
} else {
$this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
$this->value = substr($this->value, 0, 2);
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
//$this->value = substr($this->value, 0, 2);
}
}

Expand All @@ -363,30 +363,24 @@ function yy_r1_18($yy_subpatterns)
}

function yy_r1_19($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
}

function yy_r1_20($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}

function yy_r1_21($yy_subpatterns)
function yy_r1_20($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
}

function yy_r1_22($yy_subpatterns)
function yy_r1_21($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
}

function yy_r1_23($yy_subpatterns)
function yy_r1_22($yy_subpatterns)
{

$phpEndScript = $this->is_phpScript ? '|<\\/script>' : '';
Expand Down Expand Up @@ -962,19 +956,14 @@ function yy_r2_76($yy_subpatterns)
public function yylex3()
{
$tokenMap = array(
1 => 0,
2 => 0,
3 => 2,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
10 => 0,
1 => 0,
2 => 0,
3 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/literal\\s*" . $this->rdel . ")|\G((<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|(<\\?(?:php\\w+|=|[a-zA-Z]+)?))|\G(\\?>)|\G(<\/script>)|\G(<%)|\G(%>)|\G([\S\s])/iS";
$yy_global_pattern = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/literal\\s*" . $this->rdel . ")|\G([\S\s])/iS";

do {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
Expand Down Expand Up @@ -1027,19 +1016,16 @@ public function yylex3()
function yy_r3_1($yy_subpatterns)
{

if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
} else {
$this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
$this->yypushstate(self::LITERAL);
}
$this->literal_cnt ++;
$this->token = Smarty_Internal_Templateparser::TP_LITERAL;
}

function yy_r3_2($yy_subpatterns)
{

if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
if ($this->literal_cnt) {
$this->literal_cnt --;
$this->token = Smarty_Internal_Templateparser::TP_LITERAL;
} else {
$this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
$this->yypopstate();
Expand All @@ -1049,47 +1035,8 @@ function yy_r3_2($yy_subpatterns)
function yy_r3_3($yy_subpatterns)
{

if (in_array($this->value, Array('<?', '<?=', '<?php')) || $script = strpos($this->value, '<s') === 0) {
if ($script) {
$this->is_phpScript = true;
}
$this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
} else {
$this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
$this->value = substr($this->value, 0, 2);
}
}

function yy_r3_6($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
}

function yy_r3_7($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
}

function yy_r3_8($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
}

function yy_r3_9($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
}

function yy_r3_10($yy_subpatterns)
{

$phpEndScript = $this->is_phpScript ? '|<\\/script>' : '';
$to = strlen($this->data);
preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>{$phpEndScript}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
preg_match("/{$this->ldel}\/?literal{$this->rdel}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
Expand All @@ -1111,13 +1058,15 @@ public function yylex4()
8 => 0,
9 => 0,
10 => 0,
11 => 3,
15 => 0,
11 => 0,
12 => 0,
13 => 3,
17 => 0,
);
if ($this->counter >= strlen($this->data)) {
return false; // end of input
}
$yy_global_pattern = "/\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G(\")|\G(`\\$)|\G(\\$[0-9]*[a-zA-Z_]\\w*)|\G(\\$)|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/iS";
$yy_global_pattern = "/\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G(\")|\G(`\\$)|\G(\\$[0-9]*[a-zA-Z_]\\w*)|\G(\\$)|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/iS";

do {
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
Expand Down Expand Up @@ -1204,6 +1153,18 @@ function yy_r4_4($yy_subpatterns)
}

function yy_r4_5($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}

function yy_r4_6($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}

function yy_r4_7($yy_subpatterns)
{

if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
Expand All @@ -1215,7 +1176,7 @@ function yy_r4_5($yy_subpatterns)
}
}

function yy_r4_6($yy_subpatterns)
function yy_r4_8($yy_subpatterns)
{

if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
Expand All @@ -1227,14 +1188,14 @@ function yy_r4_6($yy_subpatterns)
}
}

function yy_r4_7($yy_subpatterns)
function yy_r4_9($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_QUOTE;
$this->yypopstate();
}

function yy_r4_8($yy_subpatterns)
function yy_r4_10($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_BACKTICK;
Expand All @@ -1243,25 +1204,25 @@ function yy_r4_8($yy_subpatterns)
$this->taglineno = $this->line;
}

function yy_r4_9($yy_subpatterns)
function yy_r4_11($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_DOLLARID;
}

function yy_r4_10($yy_subpatterns)
function yy_r4_12($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}

function yy_r4_11($yy_subpatterns)
function yy_r4_13($yy_subpatterns)
{

$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}

function yy_r4_15($yy_subpatterns)
function yy_r4_17($yy_subpatterns)
{

$to = strlen($this->data);
Expand Down
60 changes: 19 additions & 41 deletions smarty_internal_templatelexer.plex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public $is_phpScript = false;
public $state = 1;
public $smarty;
public $literal_cnt = 0;
private $heredoc_id_stack = Array();
public $yyTraceFILE;
public $yyTracePrompt;
Expand Down Expand Up @@ -280,16 +281,16 @@
}
}
phpstarttag {
if (in_array($this->value, Array('<?', '<?=', '<?php')) || $script = strpos($this->value, '<s') === 0) {
if ($script) {
if (($script = strpos($this->value, '<s') === 0) || in_array($this->value, Array('<?', '<?=', '<?php'))) {
if ($script) {
$this->is_phpScript = true;
}
}
$this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
} elseif ($this->value == '<?xml') {
$this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
} else {
$this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
$this->value = substr($this->value, 0, 2);
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
//$this->value = substr($this->value, 0, 2);
}
}
phpendtag {
Expand All @@ -298,9 +299,6 @@
phpendscript {
$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
}
phpendscript {
$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
}
rdel {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
Expand Down Expand Up @@ -571,48 +569,21 @@
/*!lex2php
%statename LITERAL
ldel literal rdel {
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
} else {
$this->token = Smarty_Internal_Templateparser::TP_LITERALSTART;
$this->yypushstate(self::LITERAL);
}
$this->literal_cnt++;
$this->token = Smarty_Internal_Templateparser::TP_LITERAL;
}
ldel slash literal rdel {
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
if ($this->literal_cnt) {
$this->literal_cnt--;
$this->token = Smarty_Internal_Templateparser::TP_LITERAL;
} else {
$this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
$this->yypopstate();
}
}
phpstarttag {
if (in_array($this->value, Array('<?', '<?=', '<?php')) || $script = strpos($this->value, '<s') === 0) {
if ($script) {
$this->is_phpScript = true;
}
$this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
} else {
$this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG;
$this->value = substr($this->value, 0, 2);
}
}
phpendtag {
$this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
}
phpendscript {
$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
}
aspstarttag {
$this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
}
aspendtag {
$this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
}
text {
$phpEndScript = $this->is_phpScript ? '|<\\/script>' : '';
$to = strlen($this->data);
preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>{$phpEndScript}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
preg_match("/{$this->ldel}\/?literal{$this->rdel}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1];
} else {
Expand Down Expand Up @@ -651,6 +622,13 @@
$this->taglineno = $this->line;
}
}
ldel literal rdel {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
ldel slash literal rdel {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}

ldel slash {
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
Expand Down
Loading

0 comments on commit 84a1cf0

Please sign in to comment.