diff --git a/change_log.txt b/change_log.txt index c7f3cf07..38d876f7 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,8 @@ ===== trunk ===== +21.08.2012 +- bugfix $auto_literal = false did not work with { block} tags in child templates + (problem was reintroduced after fix in 3.1.7)(Forum Topic 20581) + 17.08.2012 - bugfix compiled code of nocache sections could contain wrong escaping (Forum Topic 22810) diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 03abf493..b1d94517 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -78,7 +78,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { public static function saveBlockData($block_content, $block_tag, $template, $filepath) { $_rdl = preg_quote($template->smarty->right_delimiter); $_ldl = preg_quote($template->smarty->left_delimiter); - if ($template->smarty->auto_literal) { + if (!$template->smarty->auto_literal) { $al = '\s*'; } else { $al = ''; @@ -90,7 +90,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { $_name = trim($_match[3], '\'"'); if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child} // do we have {$smart.block.child} in nested {block} tags? - if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?)(hide)?(\s*{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) { + if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?)(hide)?(\s*{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})([\s\S]*?{$_ldl}{$al}/block\s*{$_rdl})!", $block_content, $_match2)) { foreach ($_match2[3] as $key => $name) { // get it's replacement $_name2 = trim($name, '\'"'); @@ -101,17 +101,17 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { $replacement = ''; } // replace {$smarty.block.child} tag - $search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?)({$_ldl}{$al}/block{$_rdl})%", "/§§§child§§§/"); + $search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})([\s\S]*?)({$_ldl}{$al}/block\s*{$_rdl})%", "/§§§child§§§/"); $replace = array('\2§§§child§§§\4', $replacement); $block_content = preg_replace($search, $replace, $block_content); } else { // remove hidden blocks - $block_content = preg_replace("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl}[\s\S]*?{$_ldl}{$al}/block{$_rdl})%", '', $block_content); + $block_content = preg_replace("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl}[\s\S]*?{$_ldl}{$al}/block\s*{$_rdl})%", '', $block_content); } } } // do we have not nested {$smart.block.child} - if (0 != preg_match("/({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})/", $block_content, $_match2)) { + if (0 != preg_match("/({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})/", $block_content, $_match2)) { // get child replacement for this block if (isset($template->block_data[$_name])) { $replacement = $template->block_data[$_name]['source']; @@ -119,7 +119,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { } else { $replacement = ''; } - $block_content = preg_replace("/({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})/", $replacement, $block_content); + $block_content = preg_replace("/({$_ldl}{$al}\\\$smarty\.block\.child\s*{$_rdl})/", $replacement, $block_content); } if (isset($template->block_data[$_name])) { if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { diff --git a/libs/sysplugins/smarty_internal_compile_extends.php b/libs/sysplugins/smarty_internal_compile_extends.php index 9042aa23..b93139bf 100644 --- a/libs/sysplugins/smarty_internal_compile_extends.php +++ b/libs/sysplugins/smarty_internal_compile_extends.php @@ -51,6 +51,11 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { static $_is_stringy = array('string' => true, 'eval' => true); $this->_rdl = preg_quote($compiler->smarty->right_delimiter); $this->_ldl = preg_quote($compiler->smarty->left_delimiter); + if (!$compiler->smarty->auto_literal) { + $al = '\s*'; + } else { + $al = ''; + } $filepath = $compiler->template->source->filepath; $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; // check and get attributes @@ -78,11 +83,11 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { } $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type); $_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)) { + if (preg_match_all("!({$this->_ldl}{$al}block\s(.+?)\s*{$this->_rdl})!", $_content, $s) != + preg_match_all("!({$this->_ldl}{$al}/block\s*{$this->_rdl})!", $_content, $c)) { $compiler->trigger_template_error('unmatched {block} {/block} pairs'); } - preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}|{$this->_ldl}\*([\S\s]*?)\*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE); + preg_match_all("!{$this->_ldl}{$al}block\s(.+?)\s*{$this->_rdl}|{$this->_ldl}{$al}/block\s*{$this->_rdl}|{$this->_ldl}\*([\S\s]*?)\*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE); $_result_count = count($_result[0]); $_start = 0; while ($_start+1 < $_result_count) { diff --git a/libs/sysplugins/smarty_internal_resource_extends.php b/libs/sysplugins/smarty_internal_resource_extends.php index 9481d992..29734ae0 100644 --- a/libs/sysplugins/smarty_internal_resource_extends.php +++ b/libs/sysplugins/smarty_internal_resource_extends.php @@ -89,6 +89,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource { $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; $_rdl = preg_quote($source->smarty->right_delimiter); $_ldl = preg_quote($source->smarty->left_delimiter); + if (!$source->smarty->auto_literal) { + $al = '\s*'; + } else { + $al = ''; + } $_components = array_reverse($source->components); $_first = reset($_components); $_last = end($_components); @@ -105,11 +110,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource { // extend sources if ($_component != $_last) { - if (preg_match_all("!({$_ldl}block\s(.+?){$_rdl})!", $_content, $_open) != - preg_match_all("!({$_ldl}/block{$_rdl})!", $_content, $_close)) { + if (preg_match_all("!({$_ldl}{$al}block\s(.+?)\s*{$_rdl})!", $_content, $_open) != + preg_match_all("!({$_ldl}{$al}/block\s*{$_rdl})!", $_content, $_close)) { throw new SmartyException("unmatched {block} {/block} pairs in template {$_component->type} '{$_component->name}'"); } - preg_match_all("!{$_ldl}block\s(.+?){$_rdl}|{$_ldl}/block{$_rdl}|{$_ldl}\*([\S\s]*?)\*{$_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE); + preg_match_all("!{$_ldl}{$al}block\s(.+?)\s*{$_rdl}|{$_ldl}{$al}/block\s*{$_rdl}|{$_ldl}\*([\S\s]*?)\*{$_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE); $_result_count = count($_result[0]); $_start = 0; while ($_start+1 < $_result_count) { diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index bfc413ae..e967dc77 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -141,11 +141,12 @@ class Smarty_Internal_Templatelexer 21 => 0, 22 => 0, 23 => 0, + 24 => 0, ); 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"; + $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(".$this->rdel.")|\G(<%)|\G(%>)|\G([\S\s])/iS"; do { 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)) { @@ -344,16 +345,21 @@ class Smarty_Internal_Templatelexer function yy_r1_21($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; + $this->token = Smarty_Internal_Templateparser::TP_TEXT; } function yy_r1_22($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; + $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; } function yy_r1_23($yy_subpatterns) { + $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; + } + function yy_r1_24($yy_subpatterns) + { + if ($this->mbstring_overload) { $to = mb_strlen($this->data,'latin1'); } else { @@ -1187,4 +1193,3 @@ class Smarty_Internal_Templatelexer } } -?> \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index 9695ac63..d67be6e6 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -3252,4 +3252,3 @@ static public $yy_action = array( } while ($yymajor != self::YYNOCODE && $this->yyidx >= 0); } } -?> \ No newline at end of file