mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-09 21:04:28 +02:00
fix problem with php open tags generated from tag interleaving
This commit is contained in:
@@ -241,7 +241,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$rdq = preg_quote($this->right_delimiter, '~');
|
$rdq = preg_quote($this->right_delimiter, '~');
|
||||||
|
|
||||||
/* un-hide hidden xml open tags */
|
/* un-hide hidden xml open tags */
|
||||||
$source_content = preg_replace("~<({$ldq}(.*?){$rdq})[?]~s", '< \\1', $source_content);
|
$source_content = preg_replace("~<({$ldq}(.*?){$rdq}\?)~s", '< \\1', $source_content);
|
||||||
|
|
||||||
// run template source through prefilter functions
|
// run template source through prefilter functions
|
||||||
if (count($this->_plugins['prefilter']) > 0) {
|
if (count($this->_plugins['prefilter']) > 0) {
|
||||||
@@ -353,15 +353,26 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
$compiled_content = '';
|
$compiled_content = '';
|
||||||
|
|
||||||
|
$tmp_id = '{'.md5(uniqid(rand(), true)).'}';
|
||||||
|
|
||||||
/* Interleave the compiled contents and text blocks to get the final result. */
|
/* Interleave the compiled contents and text blocks to get the final result. */
|
||||||
for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
|
for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
|
||||||
if ($compiled_tags[$i] == '') {
|
if ($compiled_tags[$i] == '') {
|
||||||
// tag result empty, remove first newline from following text block
|
// tag result empty, remove first newline from following text block
|
||||||
$text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]);
|
$text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]);
|
||||||
}
|
}
|
||||||
|
// replace legit PHP tags with placeholder
|
||||||
|
$text_blocks[$i] = str_replace('<?',$tmp_id,$text_blocks[$i]);
|
||||||
|
$compiled_tags[$i] = str_replace('<?',$tmp_id,$compiled_tags[$i]);
|
||||||
|
|
||||||
$compiled_content .= $text_blocks[$i].$compiled_tags[$i];
|
$compiled_content .= $text_blocks[$i].$compiled_tags[$i];
|
||||||
}
|
}
|
||||||
$compiled_content .= $text_blocks[$i];
|
$compiled_content .= $text_blocks[$i];
|
||||||
|
|
||||||
|
// escape created php tags
|
||||||
|
$compiled_content = str_replace('<?',"<?php echo '<?' ?>\n",$compiled_content);
|
||||||
|
// unescape legit tags
|
||||||
|
$compiled_content = str_replace($tmp_id,'<?',$compiled_content);
|
||||||
|
|
||||||
// remove \n from the end of the file, if any
|
// remove \n from the end of the file, if any
|
||||||
if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) {
|
if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) {
|
||||||
@@ -372,9 +383,11 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content;
|
$compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// remove unnecessary close/open tags
|
// remove unnecessary close/open tags
|
||||||
$compiled_content = preg_replace('~\?>\n?<\?php~', '', $compiled_content);
|
$compiled_content = preg_replace('~\?>\n?<\?php~', '', $compiled_content);
|
||||||
|
*/
|
||||||
|
|
||||||
// run compiled template through postfilter functions
|
// run compiled template through postfilter functions
|
||||||
if (count($this->_plugins['postfilter']) > 0) {
|
if (count($this->_plugins['postfilter']) > 0) {
|
||||||
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
|
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
|
||||||
|
Reference in New Issue
Block a user