- create exception on recursive {extends} calls

- fixed reported line number at "unexpected closing tag " exception
- bugfix on escape:'mail' modifier
- drop exception if 'item' variable is equal 'from' variable in {foreach} tag
This commit is contained in:
Uwe.Tews
2010-07-06 20:00:41 +00:00
parent cbe2f3356f
commit c83ef6792c
6 changed files with 85 additions and 63 deletions

View File

@@ -1,3 +1,9 @@
06/07/2010
- create exception on recursive {extends} calls
- fixed reported line number at "unexpected closing tag " exception
- bugfix on escape:'mail' modifier
- drop exception if 'item' variable is equal 'from' variable in {foreach} tag
01/07/2010
- removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins

View File

@@ -23,10 +23,13 @@
*/
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET)
{
if (!function_exists('mb_str_replace') && function_exists('mb_strlen')) {
if (!function_exists('mb_str_replace')) {
// simulate the missing PHP mb_str_replace function
function mb_str_replace($needle, $replacement, $haystack)
function mb_str_replace($needles, $replacements, $haystack)
{
$rep = (array)$replacements;
foreach ((array)$needles as $key => $needle) {
$replacement = $rep[$key];
$needle_len = mb_strlen($needle);
$replacement_len = mb_strlen($replacement);
$pos = mb_strpos($haystack, $needle, 0);
@@ -35,6 +38,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_
. mb_substr($haystack, $pos + $needle_len);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
}
}
return $haystack;
}
}
@@ -83,7 +87,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_
case 'mail':
// safe way to display e-mail address on a web page
if (function_exists('mb_str_replace')) {
if (function_exists('mb_substr')) {
return mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
} else {
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);

View File

@@ -23,10 +23,13 @@
*/
function smarty_modifier_replace($string, $search, $replace)
{
if (!function_exists("mb_str_replace")) {
if (!function_exists('mb_str_replace')) {
// simulate the missing PHP mb_str_replace function
function mb_str_replace($needle, $replacement, $haystack)
function mb_str_replace($needles, $replacements, $haystack)
{
$rep = (array)$replacements;
foreach ((array)$needles as $key => $needle) {
$replacement = $rep[$key];
$needle_len = mb_strlen($needle);
$replacement_len = mb_strlen($replacement);
$pos = mb_strpos($haystack, $needle, 0);
@@ -35,6 +38,7 @@ function smarty_modifier_replace($string, $search, $replace)
. mb_substr($haystack, $pos + $needle_len);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
}
}
return $haystack;
}
}

View File

@@ -35,7 +35,11 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
// create template object
$_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template);
// save file dependency
$compiler->template->properties['file_dependency'][sha1($_template->getTemplateFilepath())] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
$template_sha1 = sha1($_template->getTemplateFilepath());
if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
$this->compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"",$compiler->lex->line-1);
}
$compiler->template->properties['file_dependency'][$template_sha1] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
$_content = $compiler->template->template_source;
if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_content, $c)) {

View File

@@ -31,6 +31,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
$from = $_attr['from'];
$item = $_attr['item'];
if (substr_compare("\$_smarty_tpl->getVariable($item)", $from,0, strlen("\$_smarty_tpl->getVariable($item)")) == 0) {
$this->compiler->trigger_template_error("item parameter {$item} may not be the same parameter at 'from'");
}
if (isset($_attr['key'])) {
$key = $_attr['key'];
} else {

View File

@@ -95,7 +95,7 @@ abstract class Smarty_Internal_CompileBase
return;
}
// wrong nesting of tags
$this->compiler->trigger_template_error("unexpected closing tag");
$this->compiler->trigger_template_error("unexpected closing tag",$this->compiler->lex->taglineno);
return;
}
}