From d6abd3155dd743d69c9057ff8c766a8670dd2b4d Mon Sep 17 00:00:00 2001 From: "uwe.tews@googlemail.com" Date: Thu, 22 Dec 2011 19:37:44 +0000 Subject: [PATCH] - bugfix template inheritace did fail if mbstring.func_overload != 0 (issue 70) (Forum Topic 20680) --- change_log.txt | 1 + .../smarty_internal_compile_extends.php | 15 +++++++++++---- .../smarty_internal_resource_extends.php | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/change_log.txt b/change_log.txt index 1230c72d..97e740ac 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +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) +- bugfix template inheritace 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 diff --git a/libs/sysplugins/smarty_internal_compile_extends.php b/libs/sysplugins/smarty_internal_compile_extends.php index 8a4deeed..9042aa23 100644 --- a/libs/sysplugins/smarty_internal_compile_extends.php +++ b/libs/sysplugins/smarty_internal_compile_extends.php @@ -32,6 +32,12 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { * @see Smarty_Internal_CompileBase */ public $shorttag_order = array('file'); + /** + * mbstring.overload flag + * + * @var int + */ + public $mbstring_overload = 0; /** * Compiles code for the {extends} tag @@ -46,6 +52,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { $this->_rdl = preg_quote($compiler->smarty->right_delimiter); $this->_ldl = preg_quote($compiler->smarty->left_delimiter); $filepath = $compiler->template->source->filepath; + $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; // check and get attributes $_attr = $this->getAttributes($compiler, $args); if ($_attr['nocache'] === true) { @@ -70,7 +77,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { $compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 1); } $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type); - $_content = substr($compiler->template->source->content, $compiler->lex->counter - 1); + $_content = ($this->mbstring_overload ? mb_substr($compiler->template->source->content, $compiler->lex->counter - 1, 20000000, 'latin1') : substr($compiler->template->source->content, $compiler->lex->counter - 1)); if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) != preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) { $compiler->trigger_template_error('unmatched {block} {/block} pairs'); @@ -81,13 +88,13 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { while ($_start+1 < $_result_count) { $_end = 0; $_level = 1; - if (substr($_result[0][$_start][0],0,strlen($compiler->smarty->left_delimiter)+1) == $compiler->smarty->left_delimiter.'*') { + if (($this->mbstring_overload ? mb_substr($_result[0][$_start][0],0,mb_strlen($compiler->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start][0],0,strlen($compiler->smarty->left_delimiter)+1)) == $compiler->smarty->left_delimiter.'*') { $_start++; continue; } while ($_level != 0) { $_end++; - if (substr($_result[0][$_start + $_end][0],0,strlen($compiler->smarty->left_delimiter)+1) == $compiler->smarty->left_delimiter.'*') { + if (($this->mbstring_overload ? mb_substr($_result[0][$_start + $_end][0],0,mb_strlen($compiler->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start + $_end][0],0,strlen($compiler->smarty->left_delimiter)+1)) == $compiler->smarty->left_delimiter.'*') { continue; } if (!strpos($_result[0][$_start + $_end][0], '/')) { @@ -97,7 +104,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { } } $_block_content = str_replace($compiler->smarty->left_delimiter . '$smarty.block.parent' . $compiler->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', - substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0]))); + ($this->mbstring_overload ? mb_substr($_content, $_result[0][$_start][1] + mb_strlen($_result[0][$_start][0], 'latin1'), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + mb_strlen($_result[0][$_start][0], 'latin1'), 'latin1') : substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])))); Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath); $_start = $_start + $_end + 1; } diff --git a/libs/sysplugins/smarty_internal_resource_extends.php b/libs/sysplugins/smarty_internal_resource_extends.php index 53ea3ebc..9400c00f 100644 --- a/libs/sysplugins/smarty_internal_resource_extends.php +++ b/libs/sysplugins/smarty_internal_resource_extends.php @@ -18,6 +18,13 @@ */ class Smarty_Internal_Resource_Extends extends Smarty_Resource { + /** + * mbstring.overload flag + * + * @var int + */ + public $mbstring_overload = 0; + /** * populate Source Object with meta data from Resource * @@ -79,6 +86,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource { throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); } + $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; $_rdl = preg_quote($source->smarty->right_delimiter); $_ldl = preg_quote($source->smarty->left_delimiter); $_components = array_reverse($source->components); @@ -107,13 +115,13 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource { while ($_start+1 < $_result_count) { $_end = 0; $_level = 1; - if (substr($_result[0][$_start][0],0,strlen($source->smarty->left_delimiter)+1) == $source->smarty->left_delimiter.'*') { + if (($this->mbstring_overload ? mb_substr($_result[0][$_start][0],0,mb_strlen($source->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start][0],0,strlen($source->smarty->left_delimiter)+1)) == $source->smarty->left_delimiter.'*') { $_start++; continue; } while ($_level != 0) { $_end++; - if (substr($_result[0][$_start + $_end][0],0,strlen($source->smarty->left_delimiter)+1) == $source->smarty->left_delimiter.'*') { + if (($this->mbstring_overload ? mb_substr($_result[0][$_start + $_end][0],0,mb_strlen($source->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start + $_end][0],0,strlen($source->smarty->left_delimiter)+1)) == $source->smarty->left_delimiter.'*') { continue; } if (!strpos($_result[0][$_start + $_end][0], '/')) { @@ -122,7 +130,8 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource { $_level--; } } - $_block_content = str_replace($source->smarty->left_delimiter . '$smarty.block.parent' . $source->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0]))); + $_block_content = str_replace($source->smarty->left_delimiter . '$smarty.block.parent' . $source->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', + ($this->mbstring_overload ? mb_substr($_content, $_result[0][$_start][1] + mb_strlen($_result[0][$_start][0], 'latin1'), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + mb_strlen($_result[0][$_start][0], 'latin1'), 'latin1') : substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])))); Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $source->template, $_component->filepath); $_start = $_start + $_end + 1; }