From d0929cf9159994b65ea60512e934e062aa615fd8 Mon Sep 17 00:00:00 2001 From: messju Date: Sat, 2 Oct 2004 18:03:25 +0000 Subject: [PATCH] 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! --- NEWS | 1 + libs/internals/core.write_cache_file.php | 34 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 66c14b22..28c1182f 100644 --- a/NEWS +++ b/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) diff --git a/libs/internals/core.write_cache_file.php b/libs/internals/core.write_cache_file.php index 9b3a14e3..d7a82849 100644 --- a/libs/internals/core.write_cache_file.php +++ b/libs/internals/core.write_cache_file.php @@ -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