Update Smarty to 3.1.11
Update Smarty to 3.1.11

--- a/lib/smarty/README
+++ b/lib/smarty/README
@@ -1,4 +1,4 @@
-Smarty 3.1.10
+Smarty 3.1.11
 
 Author: Monte Ohrt <monte at ohrt dot com >
 Author: Uwe Tews

--- a/lib/smarty/change_log.txt
+++ b/lib/smarty/change_log.txt
@@ -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
 - 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)

--- a/lib/smarty/libs/Smarty.class.php
+++ b/lib/smarty/libs/Smarty.class.php
@@ -28,7 +28,7 @@
  * @author Uwe Tews
  * @author Rodney Rehm
  * @package Smarty
- * @version 3.1.10
+ * @version 3.1-DEV
  */
 
 /**
@@ -113,7 +113,7 @@
     /**
      * smarty version
      */
-    const SMARTY_VERSION = 'Smarty-3.1.10';
+    const SMARTY_VERSION = 'Smarty-3.1.11';
 
     /**
      * define variable scopes

--- a/lib/smarty/libs/plugins/modifier.escape.php
+++ b/lib/smarty/libs/plugins/modifier.escape.php
@@ -23,24 +23,69 @@
  */
 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) {
         $char_set = Smarty::$_CHARSET;
     }
 
     switch ($esc_type) {
         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':
             if (Smarty::$_MBSTRING) {
                 // 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
                 return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
             }
 
             // 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':
             return rawurlencode($string);

--- a/lib/smarty/libs/plugins/modifiercompiler.escape.php
+++ b/lib/smarty/libs/plugins/modifiercompiler.escape.php
@@ -25,6 +25,11 @@
  */

 function smarty_modifiercompiler_escape($params, $compiler)

 {

+    static $_double_encode = null;

+    if ($_double_encode === null) {

+        $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');

+    }

+    

     try {

         $esc_type = smarty_literal_compiler_param($params, 1, 'html');

         $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);

@@ -36,26 +41,56 @@
 

         switch ($esc_type) {

             case 'html':

-                return 'htmlspecialchars('

-                    . $params[0] .', ENT_QUOTES, '

-                    . var_export($char_set, true) . ', '

-                    . var_export($double_encode, true) . ')';

+                if ($_double_encode) {

+                    return 'htmlspecialchars('

+                        . $params[0] .', ENT_QUOTES, '

+                        . 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':

                 if (Smarty::$_MBSTRING) {

-                    return 'mb_convert_encoding(htmlspecialchars('

-                        . $params[0] .', ENT_QUOTES, '

-                        . var_export($char_set, true) . ', '

-                        . var_export($double_encode, true)

-                        . '), "HTML-ENTITIES", '

-                        . var_export($char_set, true) . ')';

+                    if ($_double_encode) {

+                        // php >=5.3.2 - go native

+                        return 'mb_convert_encoding(htmlspecialchars('

+                            . $params[0] .', ENT_QUOTES, '

+                            . 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

-                return 'htmlentities('

-                    . $params[0] .', ENT_QUOTES, '

-                    . var_export($char_set, true) . ', '

-                    . var_export($double_encode, true) . ')';

+                if ($_double_encode) {

+                    // php >=5.3.2 - go native

+                    return 'htmlentities('

+                        . $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':

                 return 'rawurlencode(' . $params[0] . ')';


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

--- a/lib/smarty/libs/sysplugins/smarty_internal_compile_block.php
+++ b/lib/smarty/libs/sysplugins/smarty_internal_compile_block.php
@@ -1,53 +1,55 @@
 <?php
+
 /**
-* Smarty Internal Plugin Compile Block
-*
-* Compiles the {block}{/block} tags
-*
-* @package Smarty
-* @subpackage Compiler
-* @author Uwe Tews
-*/
+ * Smarty Internal Plugin Compile Block
+ *
+ * Compiles the {block}{/block} tags
+ *
+ * @package Smarty
+ * @subpackage Compiler
+ * @author Uwe Tews
+ */
 
 /**
-* Smarty Internal Plugin Compile Block Class
-*
-* @package Smarty
-* @subpackage Compiler
-*/
+ * Smarty Internal Plugin Compile Block Class
+ *
+ * @package Smarty
+ * @subpackage Compiler
+ */
 class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
 
     /**
-    * Attribute definition: Overwrites base class.
-    *
-    * @var array
-    * @see Smarty_Internal_CompileBase
-    */
+     * Attribute definition: Overwrites base class.
+     *
+     * @var array
+     * @see Smarty_Internal_CompileBase
+     */
     public $required_attributes = array('name');
-    /**
-    * Attribute definition: Overwrites base class.
-    *
-    * @var array
-    * @see Smarty_Internal_CompileBase
-    */
+
+    /**
+     * Attribute definition: Overwrites base class.
+     *
+     * @var array
+     * @see Smarty_Internal_CompileBase
+     */
     public $shorttag_order = array('name', 'hide');
-    /**
-    * Attribute definition: Overwrites base class.
-    *
-    * @var array
-    * @see Smarty_Internal_CompileBase
-    */
+
+    /**
+     * Attribute definition: Overwrites base class.
+     *
+     * @var array
+     * @see Smarty_Internal_CompileBase
+     */
     public $optional_attributes = array('hide');
 
     /**
-    * Compiles code for the {block} tag
-    *
-    * @param array  $args     array with attributes from parser
-    * @param object $compiler compiler object
-    * @return boolean true
-    */
-    public function compile($args, $compiler)
-    {
+     * Compiles code for the {block} tag
+     *
+     * @param array  $args     array with attributes from parser
+     * @param object $compiler compiler object
+     * @return boolean true
+     */
+    public function compile($args, $compiler) {
         // check and get attributes
         $_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);
@@ -66,15 +68,14 @@
     }
 
     /**
-    * Save or replace child block source by block name during parsing
-    *
-    * @param string $block_content     block source content
-    * @param string $block_tag         opening block tag
-    * @param object $template          template object
-    * @param string $filepath          filepath of template source
-    */
-    public static function saveBlockData($block_content, $block_tag, $template, $filepath)
-    {
+     * Save or replace child block source by block name during parsing
+     *
+     * @param string $block_content     block source content
+     * @param string $block_tag         opening block tag
+     * @param object $template          template object
+     * @param string $filepath          filepath of template source
+     */
+    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) {
@@ -89,19 +90,24 @@
             $_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]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
-                    foreach($_match2[3] as $name) {
+                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 $key => $name) {
                         // get it's replacement
                         $_name2 = trim($name, '\'"');
-                        if (isset($template->block_data[$_name2])) {
-                            $replacement = $template->block_data[$_name2]['source'];
+                        if ($_match2[5][$key] != 'hide' || isset($template->block_data[$_name2])) {
+                            if (isset($template->block_data[$_name2])) {
+                                $replacement = $template->block_data[$_name2]['source'];
+                            } else {
+                                $replacement = '';
+                            }
+                            // replace {$smarty.block.child} tag


+                            $block_content = preg_replace($search, $replace, $block_content);
                         } 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


-                        $block_content = preg_replace($search, $replace , $block_content);
                     }
                 }
                 // do we have not nested {$smart.block.child}
@@ -118,7 +124,7 @@
                 if (isset($template->block_data[$_name])) {
                     if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
                         $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') {
                         $template->block_data[$_name]['source'] .= $block_content;
                     } elseif ($template->block_data[$_name]['mode'] == 'append') {
@@ -140,21 +146,20 @@
     }
 
     /**
-    * Compile saved child block source
-    *
-    * @param object $compiler  compiler object
-    * @param string $_name     optional name of child block
-    * @return string   compiled code of schild block
-    */
-    public static function compileChildBlock($compiler, $_name = null)
-    {
+     * Compile saved child block source
+     *
+     * @param object $compiler  compiler object
+     * @param string $_name     optional name of child block
+     * @return string   compiled code of schild block
+     */
+    public static function compileChildBlock($compiler, $_name = null) {
         $_output = '';
         // if called by {$smarty.block.child} we must search the name of enclosing {block}
         if ($_name == null) {
             $stack_count = count($compiler->_tag_stack);
             while (--$stack_count >= 0) {
                 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;
                 }
             }
@@ -168,8 +173,8 @@
         if (!isset($compiler->template->block_data[$_name]['source'])) {
             return '';
         }
-        $_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);
+        $_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);
         $_tpl->variable_filters = $compiler->template->variable_filters;
         $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
         $_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
@@ -198,14 +203,14 @@
         if ($_tpl->has_nocache_code) {
             $compiler->template->has_nocache_code = true;
         }
-        foreach($_tpl->required_plugins as $key => $tmp1) {
-            if ($compiler->nocache  && $compiler->template->caching) {
+        foreach ($_tpl->required_plugins as $key => $tmp1) {
+            if ($compiler->nocache && $compiler->template->caching) {
                 $code = 'nocache';
             } else {
                 $code = $key;
             }
-            foreach($tmp1 as $name => $tmp) {
-                foreach($tmp as $type => $data) {
+            foreach ($tmp1 as $name => $tmp) {
+                foreach ($tmp as $type => $data) {
                     $compiler->template->required_plugins[$code][$name][$type] = $data;
                 }
             }
@@ -217,22 +222,21 @@
 }
 
 /**
-* Smarty Internal Plugin Compile BlockClose Class
-*
-* @package Smarty
-* @subpackage Compiler
-*/
+ * Smarty Internal Plugin Compile BlockClose Class
+ *
+ * @package Smarty
+ * @subpackage Compiler
+ */
 class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
 
     /**
-    * Compiles code for the {/block} tag
-    *
-    * @param array  $args     array with attributes from parser
-    * @param object $compiler compiler object
-    * @return string compiled code
-    */
-    public function compile($args, $compiler)
-    {
+     * Compiles code for the {/block} tag
+     *
+     * @param array  $args     array with attributes from parser
+     * @param object $compiler compiler object
+     * @return string compiled code
+     */
+    public function compile($args, $compiler) {
         $compiler->has_code = true;
         // check and get attributes
         $_attr = $this->getAttributes($compiler, $args);
@@ -255,7 +259,7 @@
             } else {
                 $_output = $compiler->parser->current_buffer->to_smarty_php();
             }
-            unset ($compiler->template->block_data[$_name]['compiled']);
+            unset($compiler->template->block_data[$_name]['compiled']);
         }
         // reset flags
         $compiler->parser->current_buffer = $saved_data[1];

--- a/lib/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
+++ b/lib/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
@@ -108,7 +108,15 @@
                             $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];

                             // check if modifier allowed

                             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'])) {

                                 // was a plugin


--- a/lib/smarty/libs/sysplugins/smarty_internal_templateparser.php
+++ b/lib/smarty/libs/sysplugins/smarty_internal_templateparser.php
@@ -2544,7 +2544,7 @@
 #line 2540 "smarty_internal_templateparser.php"
 #line 503 "smarty_internal_templateparser.y"
     function yy_r66(){
-    $this->_retvalue = array(trim($this->yystack[$this->yyidx + -1]->minor," =\n\r")=>$this->yystack[$this->yyidx + 0]->minor);
+    $this->_retvalue = array(trim($this->yystack[$this->yyidx + -1]->minor," =\n\r\t")=>$this->yystack[$this->yyidx + 0]->minor);
     }
 #line 2545 "smarty_internal_templateparser.php"
 #line 511 "smarty_internal_templateparser.y"

comments