Re: [SMARTY-DEV] Evil e
| From: | Danilo Buerger | Date: | Fri, 09 Feb 2007 13:38:34 +0000 |
| Subject: | Re: [SMARTY-DEV] Evil e | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-2953@lists.php.net to get a copy of this message | ||
You both have some valid points. However, since the API isnt going to change for 2.6.x (i guess). These issues should be fixed the easy way. In this case my patch could be applied or $this->_quote_replace() could be replaced with addslashes() to make this work with all delimiters.
boots schrieb:
--- messju mohr <messju@lammfellpuschen.de> wrote:On Thu, Feb 08, 2007 at 06:01:08PM +0100, Danilo Buerger wrote:This is indeed better for this circumstance but I disagree with the hypothesis. Eval is useful, though of course it can be dangerous and it does have the *potential* for danger here.I suggest applying the following patch to prevent 2 problems: a) Using the "e" pattern modifier is nearly as evil as programming cobol/e is evil, so is create_function(). if we want to clean this up, we should add a method like replace_special_blocks() to Smarty_Compiler and use this as callback together with preg_replace_callback().Agreed. And we should maybe make the compiler forbid them as well. Or we can create getters/setters for the delims and enforce it there.b) If one of the delimiters is set to "'" it could get really uglygood point. if there are more places in the compiler that cause problems we should also add to the manual of $smarty->(left|right)_delimiter that certain strings are not supported.____________________________________________________________________________________ Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=list&sid=396546091Index: Smarty_Compiler.class.php =================================================================== RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v retrieving revision 1.386 diff -r1.386 Smarty_Compiler.class.php 268,273c270,279< $source_content = preg_replace($search.'e', "'" < . $this->_quote_replace($this->left_delimiter) . 'php' < . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'" < . $this->_quote_replace($this->right_delimiter) < . "'" < , $source_content);---"\n")) . \''$source_content = preg_replace_callback( $search, create_function( '$matches', 'return \'' . addslashes($this->left_delimiter) . 'php' . '\' . str_repeat("\n", substr_count($matches[0],. addslashes($this->right_delimiter) . '\';' ), $source_content );