diff --git a/change_log.txt b/change_log.txt index e467688a..1230c72d 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +22.12.2011 +- bugfix the new lexer of 17.12.2011 did fail if mbstring.func_overload != 0 (issue 70) (Forum Topic 20680) + 20.12.2011 - bugfix template inheritance: {$smarty.block.child} in nested child {block} tags did not return content after {$smarty.block.child} (Forum Topic 20564) diff --git a/libs/sysplugins/smarty_internal_configfilelexer.php b/libs/sysplugins/smarty_internal_configfilelexer.php index 326d8f97..bade2fe7 100644 --- a/libs/sysplugins/smarty_internal_configfilelexer.php +++ b/libs/sysplugins/smarty_internal_configfilelexer.php @@ -83,13 +83,13 @@ class Smarty_Internal_Configfilelexer 7 => 0, 8 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -109,7 +109,7 @@ class Smarty_Internal_Configfilelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r1_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -118,9 +118,9 @@ class Smarty_Internal_Configfilelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -195,13 +195,13 @@ class Smarty_Internal_Configfilelexer 8 => 0, 9 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G([ \t\r]+)|\G(\\d+\\.\\d+(?=[ \t\r]*[\n#;]))|\G(\\d+(?=[ \t\r]*[\n#;]))|\G(\"\"\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'(?=[ \t\r]*[\n#;]))|\G(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"(?=[ \t\r]*[\n#;]))|\G([a-zA-Z]+(?=[ \t\r]*[\n#;]))|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -221,7 +221,7 @@ class Smarty_Internal_Configfilelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r2_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -230,9 +230,9 @@ class Smarty_Internal_Configfilelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -316,13 +316,13 @@ class Smarty_Internal_Configfilelexer $tokenMap = array ( 1 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G([^\n]+?(?=[ \t\r]*\n))/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -342,7 +342,7 @@ class Smarty_Internal_Configfilelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r3_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -351,9 +351,9 @@ class Smarty_Internal_Configfilelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -385,13 +385,13 @@ class Smarty_Internal_Configfilelexer 2 => 0, 3 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G([ \t\r]+)|\G([^\n]+?(?=[ \t\r]*\n))|\G(\n)/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -411,7 +411,7 @@ class Smarty_Internal_Configfilelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r4_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -420,9 +420,9 @@ class Smarty_Internal_Configfilelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -463,13 +463,13 @@ class Smarty_Internal_Configfilelexer 1 => 0, 2 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G(\\.)|\G(.*?(?=[\.=[\]\r\n]))/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -489,7 +489,7 @@ class Smarty_Internal_Configfilelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r5_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -498,9 +498,9 @@ class Smarty_Internal_Configfilelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -535,13 +535,13 @@ class Smarty_Internal_Configfilelexer 1 => 0, 2 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G(\"\"\"(?=[ \t\r]*[\n#;]))|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -561,7 +561,7 @@ class Smarty_Internal_Configfilelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r6_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -570,9 +570,9 @@ class Smarty_Internal_Configfilelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -598,12 +598,22 @@ class Smarty_Internal_Configfilelexer function yy_r6_2($yy_subpatterns) { - $to = strlen($this->data); + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } preg_match("/\"\"\"[ \t\r]*[\n#;]/",$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"); + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); } - $this->value = substr($this->data,$this->counter,$to-$this->counter); $this->token = Smarty_Internal_Configfileparser::TPC_TRIPPLE_TEXT; } diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index fde9b7d1..5e404124 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -142,13 +142,13 @@ class Smarty_Internal_Templatelexer 22 => 0, 23 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G(".$this->ldel."[$]smarty\\.block\\.child".$this->rdel.")|\G(\\{\\})|\G(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|\G(".$this->ldel."strip".$this->rdel.")|\G(".$this->ldel."\\s{1,}strip\\s{1,}".$this->rdel.")|\G(".$this->ldel."\/strip".$this->rdel.")|\G(".$this->ldel."\\s{1,}\/strip\\s{1,}".$this->rdel.")|\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s{1,}\/)|\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{1,})|\G(".$this->ldel."\/)|\G(".$this->ldel.")|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(<%)|\G(%>)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -168,7 +168,7 @@ class Smarty_Internal_Templatelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r1_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -177,9 +177,9 @@ class Smarty_Internal_Templatelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -354,12 +354,20 @@ class Smarty_Internal_Templatelexer function yy_r1_23($yy_subpatterns) { - $to = strlen($this->data); + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } preg_match("/{$this->ldel}|<\?|\?>|<%|%>/",$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); + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } $this->token = Smarty_Internal_Templateparser::TP_TEXT; } @@ -435,13 +443,13 @@ class Smarty_Internal_Templatelexer 75 => 0, 76 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G(".$this->ldel."\\s{1,}\/)|\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{1,})|\G(\\s{1,}".$this->rdel.")|\G(".$this->ldel."\/)|\G(".$this->ldel.")|\G(".$this->rdel.")|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*===\\s*)|\G(\\s*!==\\s*)|\G(\\s*==\\s*|\\s+eq\\s+)|\G(\\s*!=\\s*|\\s*<>\\s*|\\s+(ne|neq)\\s+)|\G(\\s*>=\\s*|\\s+(ge|gte)\\s+)|\G(\\s*<=\\s*|\\s+(le|lte)\\s+)|\G(\\s*>\\s*|\\s+gt\\s+)|\G(\\s*<\\s*|\\s+lt\\s+)|\G(\\s+mod\\s+)|\G(!\\s*|not\\s+)|\G(\\s*&&\\s*|\\s*and\\s+)|\G(\\s*\\|\\|\\s*|\\s*or\\s+)|\G(\\s*xor\\s+)|\G(\\s+is\\s+odd\\s+by\\s+)|\G(\\s+is\\s+not\\s+odd\\s+by\\s+)|\G(\\s+is\\s+odd)|\G(\\s+is\\s+not\\s+odd)|\G(\\s+is\\s+even\\s+by\\s+)|\G(\\s+is\\s+not\\s+even\\s+by\\s+)|\G(\\s+is\\s+even)|\G(\\s+is\\s+not\\s+even)|\G(\\s+is\\s+div\\s+by\\s+)|\G(\\s+is\\s+not\\s+div\\s+by\\s+)|\G(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|\G(\\s*\\(\\s*)|\G(\\s*\\))|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*->\\s*)|\G(\\s*=>\\s*)|\G(\\s*=\\s*)|\G(\\+\\+|--)|\G(\\s*(\\+|-)\\s*)|\G(\\s*(\\*|\/|%)\\s*)|\G(\\$)|\G(\\s*;)|\G(::)|\G(\\s*:\\s*)|\G(@)|\G(#)|\G(\")|\G(`)|\G(\\|)|\G(\\.)|\G(\\s*,\\s*)|\G(\\s*&\\s*)|\G(\\s*\\?\\s*)|\G(0[xX][0-9a-fA-F]+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G(\\s+)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -461,7 +469,7 @@ class Smarty_Internal_Templatelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r2_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -470,9 +478,9 @@ class Smarty_Internal_Templatelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -875,13 +883,13 @@ class Smarty_Internal_Templatelexer 6 => 0, 7 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): 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(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(<%)|\G(%>)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -901,7 +909,7 @@ class Smarty_Internal_Templatelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r3_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -910,9 +918,9 @@ class Smarty_Internal_Templatelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -968,15 +976,22 @@ class Smarty_Internal_Templatelexer function yy_r3_7($yy_subpatterns) { - $to = strlen($this->data); + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } 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 { $this->compiler->trigger_template_error ("missing or misspelled literal closing tag"); } - - $this->value = substr($this->data,$this->counter,$to-$this->counter); + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } $this->token = Smarty_Internal_Templateparser::TP_LITERAL; } @@ -998,13 +1013,13 @@ class Smarty_Internal_Templatelexer 13 => 3, 17 => 0, ); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } $yy_global_pattern = "/\G(".$this->ldel."\\s{1,}\/)|\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{1,})|\G(".$this->ldel."\/)|\G(".$this->ldel.")|\G(\")|\G(`\\$)|\G(\\$[0-9]*[a-zA-Z_]\\w*)|\G(\\$)|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(".$this->ldel."|\\$|`\\$|\")))|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns if (!count($yymatches)) { @@ -1024,7 +1039,7 @@ class Smarty_Internal_Templatelexer $this->value = current($yymatches); // token value $r = $this->{'yy_r4_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -1033,9 +1048,9 @@ class Smarty_Internal_Templatelexer // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += strlen($this->value); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= strlen($this->data)) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } // skip this token @@ -1152,8 +1167,16 @@ class Smarty_Internal_Templatelexer function yy_r4_17($yy_subpatterns) { - $to = strlen($this->data); - $this->value = substr($this->data,$this->counter,$to-$this->counter); + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } $this->token = Smarty_Internal_Templateparser::TP_TEXT; }