add error messages

This commit is contained in:
Uwe Tews
2015-07-01 10:46:51 +02:00
parent be212a2a87
commit a756ce3d9e
2 changed files with 30 additions and 6 deletions

View File

@@ -282,6 +282,29 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
return $output; return $output;
} }
/**
* Compiles code for the {$smarty.foreach} tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
$compiler->trigger_template_error("missing or illegal \$Smarty.foreach name attribute", $compiler->lex->taglineno);
}
if ((!isset($parameter[2]) || false === $property = $compiler->getId($parameter[2])) || !in_array(strtolower($property), array('first', 'last', 'index', 'iteration', 'show', 'total'))) {
$compiler->trigger_template_error("missing or illegal \$Smarty.foreach property attribute", $compiler->lex->taglineno);
}
$property = strtolower($property);
$foreachVar = "'__foreach_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[{$foreachVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$foreachVar}]->value['{$property}'] : null)";
}
} }
/** /**

View File

@@ -25,17 +25,18 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$compiled_ref = ' '; $compiled_ref = ' ';
$variable = trim($_index[0], "'"); $variable = $compiler->getId($_index[0]);
if ($variable === false) {
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", $compiler->lex->taglineno);
}
if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) { if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) {
switch ($variable) { switch ($variable) {
case 'foreach': case 'foreach':
$name = trim($_index[1], "'"); return Smarty_Internal_Compile_Foreach::compileSpecialVariable(array(), $compiler, $_index);
$foreachVar = "'__foreach_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null)";
case 'section': case 'section':
return "\$_smarty_tpl->getVariable('smarty')->value$parameter"; return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
case 'capture': case 'capture':