summaryrefslogtreecommitdiff
path: root/lexer/smarty_internal_templatelexer.plex
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2018-09-18 04:46:30 +0200
committeruwetews <uwe.tews@googlemail.com>2018-09-18 04:46:30 +0200
commita6cb648dfc1ad1194a68636bc9d388e47fccb6f1 (patch)
tree1f579b4d547962a29571124eb28692656c0f77ed /lexer/smarty_internal_templatelexer.plex
parentdd55b23121e55a3b4f1af90a707a6c4e5969530f (diff)
downloadsmarty-a6cb648dfc1ad1194a68636bc9d388e47fccb6f1.tar.gz
smarty-a6cb648dfc1ad1194a68636bc9d388e47fccb6f1.tar.bz2
smarty-a6cb648dfc1ad1194a68636bc9d388e47fccb6f1.zip
- bugfix large plain text template sections without a Smarty tag > 700kB could
could fail in version 3.1.32 and 3.1.33 because PHP preg_match() restrictions https://github.com/smarty-php/smarty/issues/488
Diffstat (limited to 'lexer/smarty_internal_templatelexer.plex')
-rw-r--r--lexer/smarty_internal_templatelexer.plex54
1 files changed, 46 insertions, 8 deletions
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex
index 64a39310..afe1da90 100644
--- a/lexer/smarty_internal_templatelexer.plex
+++ b/lexer/smarty_internal_templatelexer.plex
@@ -210,6 +210,20 @@ class Smarty_Internal_Templatelexer
private $yy_global_pattern5 = null;
/**
+ * preg token pattern for text
+ *
+ * @var null
+ */
+ private $yy_global_text = null;
+
+ /**
+ * preg token pattern for literal
+ *
+ * @var null
+ */
+ private $yy_global_literal = null;
+
+ /**
* constructor
*
* @param string $source template source
@@ -330,8 +344,6 @@ class Smarty_Internal_Templatelexer
not = ~[!]\s*|not\s+~
typecast = ~[(](int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)[)]\s*~
double_quote = ~["]~
- 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
@@ -339,7 +351,8 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
comment {
- preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ $to = $this->dataLength;
+ preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1] + strlen($match[0][0]);
} else {
@@ -369,8 +382,17 @@ class Smarty_Internal_Templatelexer
phpstart {
$this->compiler->getTagCompiler('private_php')->parsePhp($this);
}
- text {
- $this->token = Smarty_Internal_Templateparser::TP_TEXT;
+ char {
+ if (!isset($this->yy_global_text)) {
+ $this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal|[<][?]((php\s+|=)|\s+)|[<][%]|[<][?]xml\s+|[<]script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*[>]|[?][>]|[%][>]SMARTYliteral/isS');
+ }
+ $to = $this->dataLength;
+ preg_match($this->yy_global_text, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ if (isset($match[0][1])) {
+ $to = $match[0][1];
+ }
+ $this->value = substr($this->data,$this->counter,$to-$this->counter);
+ $this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
*/
/*!lex2php
@@ -601,8 +623,19 @@ class Smarty_Internal_Templatelexer
$this->yypopstate();
}
}
- literaltext {
- $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
+ char {
+ if (!isset($this->yy_global_literal)) {
+ $this->yy_global_literal = $this->replace('/(SMARTYldel)SMARTYal[\/]?literalSMARTYrdel/isS');
+ }
+ $to = $this->dataLength;
+ preg_match($this->yy_global_literal, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
+ if (isset($match[0][1])) {
+ $to = $match[0][1];
+ } else {
+ $this->compiler->trigger_template_error ("missing or misspelled literal closing tag");
+ }
+ $this->value = substr($this->data,$this->counter,$to-$this->counter);
+ $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
}
*/
/*!lex2php
@@ -648,7 +681,12 @@ class Smarty_Internal_Templatelexer
textdoublequoted {
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
- */
+ char {
+ $to = $this->dataLength;
+ $this->value = substr($this->data,$this->counter,$to-$this->counter);
+ $this->token = Smarty_Internal_Templateparser::TP_TEXT;
+ }
+ */
}
\ No newline at end of file