mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
fixed handling of comments inside {php} and {literal}
This commit is contained in:
@@ -51,8 +51,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
/**#@+
|
/**#@+
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $_literal_blocks = array(); // keeps literal template blocks
|
var $_folded_blocks = array(); // keeps folded template blocks
|
||||||
var $_php_blocks = array(); // keeps php code blocks
|
|
||||||
var $_current_file = null; // the current template being compiled
|
var $_current_file = null; // the current template being compiled
|
||||||
var $_current_line_no = 1; // line number for error messages
|
var $_current_line_no = 1; // line number for error messages
|
||||||
var $_capture_stack = array(); // keeps track of nested capture buffers
|
var $_capture_stack = array(); // keeps track of nested capture buffers
|
||||||
@@ -254,22 +253,20 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Annihilate the comments. */
|
/* fetch all special blocks */
|
||||||
$source_content = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se",
|
$search = "!{$ldq}\*(.*?)\*{$rdq}|{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}|{$ldq}\s*php\s*{$rdq}(.*?){$ldq}\s*/php\s*{$rdq}!s";
|
||||||
"'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'",
|
|
||||||
$source_content);
|
|
||||||
|
|
||||||
/* Pull out the literal blocks. */
|
preg_match_all($search, $source_content, $match, PREG_SET_ORDER);
|
||||||
preg_match_all("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", $source_content, $_match);
|
$this->_folded_blocks = $match;
|
||||||
$this->_literal_blocks = $_match[1];
|
reset($this->_folded_blocks);
|
||||||
$source_content = preg_replace("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s",
|
|
||||||
$this->_quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $source_content);
|
|
||||||
|
|
||||||
/* Pull out the php code blocks. */
|
/* replace special blocks by "{php}" */
|
||||||
preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $source_content, $_match);
|
$source_content = preg_replace($search.'e', "'"
|
||||||
$this->_php_blocks = $_match[1];
|
. $this->_quote_replace($this->left_delimiter) . 'php'
|
||||||
$source_content = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s",
|
. "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
|
||||||
$this->_quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $source_content);
|
. $this->_quote_replace($this->right_delimiter)
|
||||||
|
. "'"
|
||||||
|
, $source_content);
|
||||||
|
|
||||||
/* Gather all template tags. */
|
/* Gather all template tags. */
|
||||||
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $source_content, $_match);
|
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $source_content, $_match);
|
||||||
@@ -531,19 +528,27 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
case 'literal':
|
|
||||||
list (,$literal_block) = each($this->_literal_blocks);
|
|
||||||
$this->_current_line_no += substr_count($literal_block, "\n");
|
|
||||||
return "<?php echo '".str_replace("'", "\'", str_replace("\\", "\\\\", $literal_block))."'; ?>" . $this->_additional_newline;
|
|
||||||
|
|
||||||
case 'php':
|
case 'php':
|
||||||
|
/* handle folded tags replaced by {php} */
|
||||||
|
list(, $block) = each($this->_folded_blocks);
|
||||||
|
$this->_current_line_no += substr_count($block[0], "\n");
|
||||||
|
/* the number of matched elements in the regexp in _compile_file()
|
||||||
|
determins the type of folded tag that was found */
|
||||||
|
switch (count($block)) {
|
||||||
|
case 2: /* comment */
|
||||||
|
return '';
|
||||||
|
|
||||||
|
case 3: /* literal */
|
||||||
|
return "<?php echo '" . strtr($block[2], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>" . $this->_additional_newline;
|
||||||
|
|
||||||
|
case 4: /* php */
|
||||||
if ($this->security && !$this->security_settings['PHP_TAGS']) {
|
if ($this->security && !$this->security_settings['PHP_TAGS']) {
|
||||||
$this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);
|
$this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list (,$php_block) = each($this->_php_blocks);
|
return '<?php ' . $block[4] .' ?>';
|
||||||
$this->_current_line_no += substr_count($php_block, "\n");
|
}
|
||||||
return '<?php '.$php_block.' ?>';
|
break;
|
||||||
|
|
||||||
case 'insert':
|
case 'insert':
|
||||||
return $this->_compile_insert_tag($tag_args);
|
return $this->_compile_insert_tag($tag_args);
|
||||||
|
Reference in New Issue
Block a user