diff options
| author | Uwe Tews <uwe.tews@googlemail.com> | 2017-10-21 13:14:14 +0200 |
|---|---|---|
| committer | Uwe Tews <uwe.tews@googlemail.com> | 2017-10-21 13:14:14 +0200 |
| commit | 3d7dece0886a64ef4a2b78e16b7b3be5a1edc37d (patch) | |
| tree | affaf281ef83d6658d393649eea96a1d9f15fa2b /lexer/smarty_internal_templatelexer.plex | |
| parent | 668d07cda94ff0b700cd40206e353fc65e6f532e (diff) | |
| download | smarty-3d7dece0886a64ef4a2b78e16b7b3be5a1edc37d.tar.gz smarty-3d7dece0886a64ef4a2b78e16b7b3be5a1edc37d.tar.bz2 smarty-3d7dece0886a64ef4a2b78e16b7b3be5a1edc37d.zip | |
- bugfix custom delimiters could fail since modification of version 3.1.32-dev-23
https://github.com/smarty-php/smarty/issues/394
Diffstat (limited to 'lexer/smarty_internal_templatelexer.plex')
| -rw-r--r-- | lexer/smarty_internal_templatelexer.plex | 120 |
1 files changed, 27 insertions, 93 deletions
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex index ea53f9e8..a92653d0 100644 --- a/lexer/smarty_internal_templatelexer.plex +++ b/lexer/smarty_internal_templatelexer.plex @@ -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 @@ -203,13 +168,6 @@ class Smarty_Internal_Templatelexer ); /** - * preg string of user defined litereals - * - * @var string - */ - public $literals = ''; - - /** * literal tag nesting level * * @var int @@ -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(); } /** @@ -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); } /** @@ -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 @@ -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*~ @@ -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+~ @@ -390,12 +328,11 @@ 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 @@ -403,11 +340,11 @@ class Smarty_Internal_Templatelexer $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; @@ -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; @@ -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; @@ -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 |
