Skip to content

Commit

Permalink
- bugfix custom delimiters could fail since modification of version 3…
Browse files Browse the repository at this point in the history
….1.32-dev-23

    #394
  • Loading branch information
uwetews committed Oct 21, 2017
1 parent 668d07c commit 3d7dece
Show file tree
Hide file tree
Showing 7 changed files with 724 additions and 796 deletions.
6 changes: 5 additions & 1 deletion change_log.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
===== 3.1.32 - dev ===
21.10.2017
- bugfix custom delimiters could fail since modification of version 3.1.32-dev-23
https://github.com/smarty-php/smarty/issues/394

18.10.2017
-bugfix fix implementation of unclosed block tag in double quoted string of 12.10.2017
- bugfix fix implementation of unclosed block tag in double quoted string of 12.10.2017
https://github.com/smarty-php/smarty/issues/396 https://github.com/smarty-php/smarty/issues/397
https://github.com/smarty-php/smarty/issues/391 https://github.com/smarty-php/smarty/issues/392

Expand Down
120 changes: 27 additions & 93 deletions lexer/smarty_internal_templatelexer.plex
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,7 @@ class Smarty_Internal_Templatelexer
*/
public $phpType = '';

/**
* escaped left delimiter
*
* @var string
*/
public $ldel = '';

/**
* escaped left delimiter with space
*
* @var string
*/
public $ldel_q = '';

/**
* escaped left delimiter length
*
* @var int
*/
public $ldel_length = 0;

/**
* escaped right delimiter
*
* @var string
*/
public $rdel = '';

/**
* escaped right delimiter length
*
* @var int
*/
public $rdel_length = 0;

/**
/**
* state number
*
* @var int
Expand Down Expand Up @@ -202,13 +167,6 @@ class Smarty_Internal_Templatelexer
'SCOND' => '"is even" ... if condition',
);

/**
* preg string of user defined litereals
*
* @var string
*/
public $literals = '';

/**
* literal tag nesting level
*
Expand Down Expand Up @@ -266,29 +224,11 @@ class Smarty_Internal_Templatelexer
$this->counter += strlen($match[0]);
}
$this->line = 1;
$this->smarty = $compiler->smarty;
$this->smarty = $compiler->template->smarty;
$this->compiler = $compiler;
$this->ldel = preg_quote($this->smarty->left_delimiter, '/') . ($this->smarty->auto_literal ? '' : '\\s*');
$this->ldel_length = strlen($this->smarty->left_delimiter);
$this->rdel = preg_quote($this->smarty->right_delimiter, '/');
$this->rdel_length = strlen($this->smarty->right_delimiter);
$this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter;
$this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter;
$literals = $this->smarty->getLiterals();
if (!empty($literals)) {
foreach ($literals as $key => $literal) {
$literals[$key] = preg_quote($literal, '/');
}
}

if ($this->smarty->auto_literal) {
$literals[] = $this->ldel . '{1,}\\s+';
}
if (!empty($literals)) {
$this->literals = implode('|', $literals);
} else {
$this->literals = preg_quote('^$', '/');
}
$this->compiler->initDelimiterPreg();
$this->smarty_token_names['LDEL'] = $this->smarty->getLeftDelimiter();
$this->smarty_token_names['RDEL'] = $this->smarty->getRightDelimiter();
}

/**
Expand All @@ -304,15 +244,13 @@ class Smarty_Internal_Templatelexer
/**
* replace placeholders with runtime preg code
*
* @param string $input
* @param string $preg
*
* @return string
*/
public function replace($input)
public function replace($preg)
{
return str_replace(array('SMARTYldel', 'SMARTYliteral', 'SMARTYrdel'),
array($this->ldel, $this->literals, $this->rdel),
$input);
return $this->compiler->replaceDelimiter($preg);
}

/**
Expand All @@ -322,8 +260,8 @@ class Smarty_Internal_Templatelexer
*/
public function isAutoLiteral()
{
return $this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ?
strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false;
return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ?
strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false;
}

/*!lex2php
Expand All @@ -332,22 +270,22 @@ class Smarty_Internal_Templatelexer
%token $this->token
%value $this->value
%line $this->line
userliteral = ~SMARTYliteral~
userliteral = ~(SMARTYldel)SMARTYautoliteral\s+SMARTYliteral~
char = ~[\S\s]~
textdoublequoted = ~([^"\\]*?)((?:\\.[^"\\]*?)*?)(?=(SMARTYliteral|SMARTYldel|\$|`\$|"))~
textdoublequoted = ~([^"\\]*?)((?:\\.[^"\\]*?)*?)(?=((SMARTYldel)SMARTYal|\$|`\$|"SMARTYliteral))~
namespace = ~([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+~
emptyjava = ~[{][}]~
phptag = ~(SMARTYldelphp([ ].*?)?SMARTYrdel)|(SMARTYldel[/]phpSMARTYrdel)~
phpstart = ~([<][?]((php\s+|=)|\s+))|([<][%])|([<][?]xml\s+)|([<]script\s+language\s*=\s*["']?\s*php\s*["']?\s*[>])|([?][>])|([%][>])~
phptag = ~(SMARTYldel)SMARTYalphp([ ].*?)?SMARTYrdel|(SMARTYldel)SMARTYal[/]phpSMARTYrdel~
phpstart = ~[<][?]((php\s+|=)|\s+)|[<][%]|[<][?]xml\s+|[<]script\s+language\s*=\s*["']?\s*php\s*["']?\s*[>]|[?][>]|[%][>]~
slash = ~[/]~
ldel = ~SMARTYldel~
ldel = ~(SMARTYldel)SMARTYal~
rdel = ~\s*SMARTYrdel~
nocacherdel = ~(\s+nocache)?\s*SMARTYrdel~
notblockid = ~(?:(?!block)[0-9]*[a-zA-Z_]\w*)~
integer = ~\d+~
hex = ~0[xX][0-9a-fA-F]+~
math = ~\s*([*]{1,2}|[%/^&]|[<>]{2})\s*~
comment = ~SMARTYldel[*]~
comment = ~(SMARTYldel)SMARTYal[*]~
incdec = ~([+]|[-]){2}~
unimath = ~\s*([+]|[-])\s*~
openP = ~\s*[(]\s*~
Expand All @@ -370,14 +308,14 @@ class Smarty_Internal_Templatelexer
backtick = ~[`]~
vert = ~[|]~
qmark = ~\s*[?]\s*~
constant = ~([_]+[A-Z0-9][0-9A-Z_]*|[A-Z][0-9A-Z_]*)(?![0-9A-Z_]*[a-z])~
constant = ~[_]+[A-Z0-9][0-9A-Z_]*|[A-Z][0-9A-Z_]*(?![0-9A-Z_]*[a-z])~
attr = ~\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\s*[=]\s*~
id = ~[0-9]*[a-zA-Z_]\w*~
literal = ~literal~
strip = ~strip~
lop = ~\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\s*~
lop = ~\s*([!=][=]{1,2}|[<][=>]?|[>][=]?|[&|]{2})\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+~
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+~
Expand All @@ -390,24 +328,23 @@ class Smarty_Internal_Templatelexer
foreach = ~foreach(?![^\s])~
setfilter = ~setfilter\s+~
instanceof = ~\s+instanceof\s+~
not = ~([!]\s*)|(not\s+)~
not = ~[!]\s*|not\s+~
typecast = ~[(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\s*~
double_quote = ~["]~
text = ~((.*?)(?=(SMARTYliteral|[{]|([<][?]((php\s+|=)|\s+))|([<][%])|([<][?]xml\s+)|([<]script\s+language\s*=\s*["']?\s*php\s*["']?\s*[>])|([?][>])|([%][>]))))|(.*)~
literaltext = ~(.*?)(?=SMARTYldel[/]?literalSMARTYrdel)~
anytext = ~.*~
text = ~(.*?)(?=((SMARTYldel)SMARTYal|[<][?]((php\s+|=)|\s+)|[<][%]|[<][?]xml\s+|[<]script\s+language\s*=\s*["']?\s*php\s*["']?\s*[>]|[?][>]|[%][>]SMARTYliteral))|[\s\S]+~
literaltext = ~(.*?)(?=(SMARTYldel)SMARTYal[/]?literalSMARTYrdel)~
*/
/*!lex2php
%statename TEXT
emptyjava {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
comment {
preg_match("/[*]{$this->rdel}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
preg_match("/[*]{$this->compiler->getRdelPreg()}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1] + strlen($match[0][0]);
} else {
$this->compiler->trigger_template_error ("missing or misspelled comment closing tag '*{$this->smarty->right_delimiter}'");
$this->compiler->trigger_template_error ("missing or misspelled comment closing tag '*{$this->smarty->getRightDelimiter()}'");
}
$this->value = substr($this->data,$this->counter,$to-$this->counter);
return false;
Expand Down Expand Up @@ -475,12 +412,12 @@ class Smarty_Internal_Templatelexer
$this->taglineno = $this->line;
}
ldel dollar id nocacherdel {
if ($this->_yy_stack[count($this->_yy_stack)-1] == self::TEXT) {
if ($this->_yy_stack[count($this->_yy_stack)-1] === self::TEXT) {
$this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT;
$this->taglineno = $this->line;
} else {
$this->value = $this->smarty->left_delimiter;
$this->value = $this->smarty->getLeftDelimiter();
$this->token = Smarty_Internal_Templateparser::TP_LDEL;
$this->yybegin(self::TAGBODY);
$this->taglineno = $this->line;
Expand Down Expand Up @@ -592,7 +529,7 @@ class Smarty_Internal_Templatelexer
}
attr {
// resolve conflicts with shorttag and right_delimiter starting with '='
if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) {
if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->compiler->getRdelLength()) === $this->smarty->getRightDelimiter()) {
preg_match("/\s+/",$this->value,$match);
$this->value = $match[0];
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
Expand Down Expand Up @@ -663,9 +600,6 @@ class Smarty_Internal_Templatelexer
literaltext {
$this->token = Smarty_Internal_Templateparser::TP_LITERAL;
}
anytext {
$this->token = Smarty_Internal_Templateparser::TP_LITERAL;
}
*/
/*!lex2php
%statename DOUBLEQUOTEDSTRING
Expand Down
Loading

0 comments on commit 3d7dece

Please sign in to comment.