mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
fixed nocache-handling with nested includes. there was a logical error
in the replacement of internal nocache-tags to dynamic content that lead to false results with deeply nested includes or with nocache-blocks inside nocache-blocks. many thanks to Lars Jankowfsky for providing big help on reproducing and tracking down this bug!
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- fixed nocache-handling with nested includes (Lars Jankowfsky, messju)
|
||||
- moved /libs/core to /libs/internals (boots)
|
||||
- fixed more parsing problems (messju)
|
||||
|
||||
|
@@ -31,12 +31,34 @@ function smarty_core_write_cache_file($params, &$smarty)
|
||||
$smarty->_cache_info['expires'] = -1;
|
||||
}
|
||||
|
||||
// collapse {nocache...}-tags
|
||||
$params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})'
|
||||
.'.*'
|
||||
.'{/nocache\:\\3#\\4\})!Us'
|
||||
,'\\2'
|
||||
,$params['results']);
|
||||
// collapse nocache.../nocache-tags
|
||||
if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
|
||||
// remove everything between every pair of outermost noache.../nocache-tags
|
||||
// and replace it by a single nocache-tag
|
||||
// this new nocache-tag will be replaced by dynamic contents in
|
||||
// smarty_core_process_compiled_includes() on a cache-read
|
||||
|
||||
$match_count = count($match[0]);
|
||||
$results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
$level = 0;
|
||||
$j = 0;
|
||||
for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) {
|
||||
if ($results[$i] == $match[0][$j]) {
|
||||
// nocache tag
|
||||
if ($match[1][$j]) { // closing tag
|
||||
$level--;
|
||||
unset($results[$i]);
|
||||
} else { // opening tag
|
||||
if ($level++ > 0) unset($results[$i]);
|
||||
}
|
||||
$j++;
|
||||
} elseif ($level > 0) {
|
||||
unset($results[$i]);
|
||||
}
|
||||
}
|
||||
$params['results'] = implode('', $results);
|
||||
}
|
||||
$smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
|
||||
|
||||
// prepend the cache header info into cache file
|
||||
|
Reference in New Issue
Block a user