1
0

Smarty 3.1.11

This commit is contained in:
Ian
2012-07-01 18:25:01 +02:00
parent ea66e5b89f
commit 03e8d3ce7b
8 changed files with 214 additions and 107 deletions

View File

@@ -1,4 +1,4 @@
Smarty 3.1.10 Smarty 3.1.11
Author: Monte Ohrt <monte at ohrt dot com > Author: Monte Ohrt <monte at ohrt dot com >
Author: Uwe Tews Author: Uwe Tews

View File

@@ -1,4 +1,18 @@
===== Smarty-3.1.10 ===== ===== trunk =====
===== Smarty-3.1.11 =====
30.06.2012
- bugfix {block.. hide} did not work as nested child (Forum Topic 22216)
25.06.2012
- bugfix the default plugin handler did not allow static class methods for modifier (issue 85)
24.06.2012
- bugfix escape modifier support for PHP < 5.2.3 (Forum Topic 21176)
11.06.2012
- bugfix the patch for Topic 21856 did break tabs between tag attributes (Forum Topic 22124)
===== Smarty-3.1.10 =====
09.06.2012 09.06.2012
- bugfix the compiler did ignore registered compiler plugins for closing tags (Forum Topic 22094) - bugfix the compiler did ignore registered compiler plugins for closing tags (Forum Topic 22094)
- bugfix the patch for Topic 21856 did break multiline tags (Forum Topic 22124) - bugfix the patch for Topic 21856 did break multiline tags (Forum Topic 22124)

View File

@@ -28,7 +28,7 @@
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
* @version 3.1.10 * @version 3.1-DEV
*/ */
/** /**
@@ -113,7 +113,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = 'Smarty-3.1.10'; const SMARTY_VERSION = 'Smarty-3.1.11';
/** /**
* define variable scopes * define variable scopes

View File

@@ -23,24 +23,69 @@
*/ */
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{ {
static $_double_encode = null;
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
if (!$char_set) { if (!$char_set) {
$char_set = Smarty::$_CHARSET; $char_set = Smarty::$_CHARSET;
} }
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); if ($_double_encode) {
// php >=5.3.2 - go native
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
// php <5.3.2 - only handle double encoding
return htmlspecialchars($string, ENT_QUOTES, $char_set);
} else {
// php <5.3.2 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
return $string;
}
}
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars() // mb_convert_encoding ignores htmlspecialchars()
$string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); if ($_double_encode) {
// php >=5.3.2 - go native
$string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
// php <5.3.2 - only handle double encoding
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
} else {
// php <5.3.2 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
return $string;
}
}
// htmlentities() won't convert everything, so use mb_convert_encoding // htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set); return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
} }
// no MBString fallback // no MBString fallback
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode); if ($_double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
} else {
if ($double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set);
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($string, ENT_QUOTES, $char_set);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
return $string;
}
}
case 'url': case 'url':
return rawurlencode($string); return rawurlencode($string);

View File

@@ -25,6 +25,11 @@ require_once( SMARTY_PLUGINS_DIR .'shared.literal_compiler_param.php' );
*/ */
function smarty_modifiercompiler_escape($params, $compiler) function smarty_modifiercompiler_escape($params, $compiler)
{ {
static $_double_encode = null;
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
try { try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html'); $esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
@@ -36,26 +41,56 @@ function smarty_modifiercompiler_escape($params, $compiler)
switch ($esc_type) { switch ($esc_type) {
case 'html': case 'html':
return 'htmlspecialchars(' if ($_double_encode) {
. $params[0] .', ENT_QUOTES, ' return 'htmlspecialchars('
. var_export($char_set, true) . ', ' . $params[0] .', ENT_QUOTES, '
. var_export($double_encode, true) . ')'; . var_export($char_set, true) . ', '
. var_export($double_encode, true) . ')';
} else if ($double_encode) {
return 'htmlspecialchars('
. $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
case 'htmlall': case 'htmlall':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
return 'mb_convert_encoding(htmlspecialchars(' if ($_double_encode) {
. $params[0] .', ENT_QUOTES, ' // php >=5.3.2 - go native
. var_export($char_set, true) . ', ' return 'mb_convert_encoding(htmlspecialchars('
. var_export($double_encode, true) . $params[0] .', ENT_QUOTES, '
. '), "HTML-ENTITIES", ' . var_export($char_set, true) . ', '
. var_export($char_set, true) . ')'; . var_export($double_encode, true)
. '), "HTML-ENTITIES", '
. var_export($char_set, true) . ')';
} else if ($double_encode) {
// php <5.3.2 - only handle double encoding
return 'mb_convert_encoding(htmlspecialchars('
. $params[0] .', ENT_QUOTES, '
. var_export($char_set, true)
. '), "HTML-ENTITIES", '
. var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
} }
// no MBString fallback // no MBString fallback
return 'htmlentities(' if ($_double_encode) {
. $params[0] .', ENT_QUOTES, ' // php >=5.3.2 - go native
. var_export($char_set, true) . ', ' return 'htmlentities('
. var_export($double_encode, true) . ')'; . $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ', '
. var_export($double_encode, true) . ')';
} else if ($double_encode) {
// php <5.3.2 - only handle double encoding
return 'htmlentities('
. $params[0] .', ENT_QUOTES, '
. var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
case 'url': case 'url':
return 'rawurlencode(' . $params[0] . ')'; return 'rawurlencode(' . $params[0] . ')';

View File

@@ -40,6 +40,7 @@ function smarty_outputfilter_trimwhitespace($source, Smarty_Internal_Template $s
} }
// Strip all HTML-Comments // Strip all HTML-Comments
// yes, even the ones in <script> - see http://stackoverflow.com/a/808850/515124
$source = preg_replace( '#<!--.*?-->#ms', '', $source ); $source = preg_replace( '#<!--.*?-->#ms', '', $source );
// capture html elements not to be messed with // capture html elements not to be messed with

View File

@@ -1,53 +1,55 @@
<?php <?php
/**
* Smarty Internal Plugin Compile Block
*
* Compiles the {block}{/block} tags
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/** /**
* Smarty Internal Plugin Compile Block Class * Smarty Internal Plugin Compile Block
* *
* @package Smarty * Compiles the {block}{/block} tags
* @subpackage Compiler *
*/ * @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Block Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name'); public $required_attributes = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('name', 'hide'); public $shorttag_order = array('name', 'hide');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
* @var array * @var array
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('hide'); public $optional_attributes = array('hide');
/** /**
* Compiles code for the {block} tag * Compiles code for the {block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return boolean true * @return boolean true
*/ */
public function compile($args, $compiler) public function compile($args, $compiler) {
{
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code); $save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code);
@@ -66,15 +68,14 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
} }
/** /**
* Save or replace child block source by block name during parsing * Save or replace child block source by block name during parsing
* *
* @param string $block_content block source content * @param string $block_content block source content
* @param string $block_tag opening block tag * @param string $block_tag opening block tag
* @param object $template template object * @param object $template template object
* @param string $filepath filepath of template source * @param string $filepath filepath of template source
*/ */
public static function saveBlockData($block_content, $block_tag, $template, $filepath) public static function saveBlockData($block_content, $block_tag, $template, $filepath) {
{
$_rdl = preg_quote($template->smarty->right_delimiter); $_rdl = preg_quote($template->smarty->right_delimiter);
$_ldl = preg_quote($template->smarty->left_delimiter); $_ldl = preg_quote($template->smarty->left_delimiter);
if ($template->smarty->auto_literal) { if ($template->smarty->auto_literal) {
@@ -89,19 +90,24 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$_name = trim($_match[3], '\'"'); $_name = trim($_match[3], '\'"');
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child} if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
// do we have {$smart.block.child} in nested {block} tags? // do we have {$smart.block.child} in nested {block} tags?
if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\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{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
foreach($_match2[3] as $name) { foreach ($_match2[3] as $key => $name) {
// get it's replacement // get it's replacement
$_name2 = trim($name, '\'"'); $_name2 = trim($name, '\'"');
if (isset($template->block_data[$_name2])) { if ($_match2[5][$key] != 'hide' || isset($template->block_data[$_name2])) {
$replacement = $template->block_data[$_name2]['source']; if (isset($template->block_data[$_name2])) {
$replacement = $template->block_data[$_name2]['source'];
} else {
$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})%", "/<2F><><EFBFBD>child<6C><64><EFBFBD>/");
$replace = array('\2<><32><EFBFBD>child<6C><64><EFBFBD>\4', $replacement);
$block_content = preg_replace($search, $replace, $block_content);
} else { } else {
$replacement = ''; // remove hidden blocks
$block_content = preg_replace("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl}[\s\S]*?{$_ldl}{$al}/block{$_rdl})%", '', $block_content);
} }
// 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})%","/<2F><><EFBFBD>child<6C><64><EFBFBD>/");
$replace = array('\2<><32><EFBFBD>child<6C><64><EFBFBD>\4', $replacement);
$block_content = preg_replace($search, $replace , $block_content);
} }
} }
// do we have not nested {$smart.block.child} // do we have not nested {$smart.block.child}
@@ -118,7 +124,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
if (isset($template->block_data[$_name])) { if (isset($template->block_data[$_name])) {
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
$template->block_data[$_name]['source'] = $template->block_data[$_name]['source'] =
str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']); str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
} elseif ($template->block_data[$_name]['mode'] == 'prepend') { } elseif ($template->block_data[$_name]['mode'] == 'prepend') {
$template->block_data[$_name]['source'] .= $block_content; $template->block_data[$_name]['source'] .= $block_content;
} elseif ($template->block_data[$_name]['mode'] == 'append') { } elseif ($template->block_data[$_name]['mode'] == 'append') {
@@ -140,21 +146,20 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
} }
/** /**
* Compile saved child block source * Compile saved child block source
* *
* @param object $compiler compiler object * @param object $compiler compiler object
* @param string $_name optional name of child block * @param string $_name optional name of child block
* @return string compiled code of schild block * @return string compiled code of schild block
*/ */
public static function compileChildBlock($compiler, $_name = null) public static function compileChildBlock($compiler, $_name = null) {
{
$_output = ''; $_output = '';
// if called by {$smarty.block.child} we must search the name of enclosing {block} // if called by {$smarty.block.child} we must search the name of enclosing {block}
if ($_name == null) { if ($_name == null) {
$stack_count = count($compiler->_tag_stack); $stack_count = count($compiler->_tag_stack);
while (--$stack_count >= 0) { while (--$stack_count >= 0) {
if ($compiler->_tag_stack[$stack_count][0] == 'block') { if ($compiler->_tag_stack[$stack_count][0] == 'block') {
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'] ,"'\""); $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "'\"");
break; break;
} }
} }
@@ -168,8 +173,8 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
if (!isset($compiler->template->block_data[$_name]['source'])) { if (!isset($compiler->template->block_data[$_name]['source'])) {
return ''; return '';
} }
$_tpl = new Smarty_Internal_template ('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
$compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime); $compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
$_tpl->variable_filters = $compiler->template->variable_filters; $_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file']; $_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
@@ -198,14 +203,14 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
if ($_tpl->has_nocache_code) { if ($_tpl->has_nocache_code) {
$compiler->template->has_nocache_code = true; $compiler->template->has_nocache_code = true;
} }
foreach($_tpl->required_plugins as $key => $tmp1) { foreach ($_tpl->required_plugins as $key => $tmp1) {
if ($compiler->nocache && $compiler->template->caching) { if ($compiler->nocache && $compiler->template->caching) {
$code = 'nocache'; $code = 'nocache';
} else { } else {
$code = $key; $code = $key;
} }
foreach($tmp1 as $name => $tmp) { foreach ($tmp1 as $name => $tmp) {
foreach($tmp as $type => $data) { foreach ($tmp as $type => $data) {
$compiler->template->required_plugins[$code][$name][$type] = $data; $compiler->template->required_plugins[$code][$name][$type] = $data;
} }
} }
@@ -217,22 +222,21 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
} }
/** /**
* Smarty Internal Plugin Compile BlockClose Class * Smarty Internal Plugin Compile BlockClose Class
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/block} tag * Compiles code for the {/block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, $compiler) {
{
$compiler->has_code = true; $compiler->has_code = true;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -255,7 +259,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
} else { } else {
$_output = $compiler->parser->current_buffer->to_smarty_php(); $_output = $compiler->parser->current_buffer->to_smarty_php();
} }
unset ($compiler->template->block_data[$_name]['compiled']); unset($compiler->template->block_data[$_name]['compiled']);
} }
// reset flags // reset flags
$compiler->parser->current_buffer = $saved_data[1]; $compiler->parser->current_buffer = $saved_data[1];

View File

@@ -108,7 +108,15 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
$output = "{$function}({$params})"; if (!is_array($function)) {
$output = "{$function}({$params})";
} else {
if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
}
}
} }
if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) { if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
// was a plugin // was a plugin