From 00d34617ccb6a53185f0e872a735b4dd2f65009b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 13:36:14 +0100 Subject: [PATCH] [ticket/11179] correct the start parameter while retrieving from cache Start parameter if not between 0 and the total result count of the cached search results is changed accordingly PHPBB3-11179 --- phpBB/includes/search/base.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index b364dead9a..11e5535979 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -97,7 +97,6 @@ class phpbb_search_base function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) { global $cache; - if (!($stored_ids = $cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key @@ -109,6 +108,19 @@ class phpbb_search_base $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; $complete = true; + // change start parameter in case out of bounds + if ($result_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + } + // change the start to the actual end of the current request if the sort direction differs // from the dirction in the cache and reverse the ids later if ($reverse_ids)