[wellwell-devel] [wellwell] Fix off-by-one error in custom paging subroutine.

Stefan Hornburg wellwell-devel at rt.icdevgroup.org
Tue Apr 24 09:15:05 UTC 2012


commit c077ddcb8c7ec897df997565ac7e1a962debbb14
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Tue Apr 24 11:14:23 2012 +0200

    Fix off-by-one error in custom paging subroutine.

 code/paging.sub |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/code/paging.sub b/code/paging.sub
index 998bd29..ab58622 100644
--- a/code/paging.sub
+++ b/code/paging.sub
@@ -33,11 +33,11 @@ sub {
         $curpage = $opt->{paging_page} || $CGI->{category_page};
 
 	if ($curpage) {
-		$first = ($curpage - 1) * $ml;
+		$first = ($curpage - 1) * $ml + 1;
 	}
-	elsif ($q->{mv_first_match}) {
-		$first = $q->{mv_first_match} || 1;
+	elsif ($q->{mv_first_match} >= $ml) {
                 $curpage = (int($q->{mv_first_match} / 20)) + 1;
+		$first = ($curpage - 1) * $ml;
 	}
 	else {
                 $first = $curpage = 1;
@@ -51,8 +51,14 @@ sub {
 	if ($r =~ /\[match/) {
 		my ($range_start, $range_end);
 
-		$range_start = $first;
-		$range_end = $first + $ml - 1;
+                if ($first > 1) {
+                    $range_start = $first + 1;
+		    $range_end = $first + $ml;
+                }
+		else {
+		    $range_start = $first;
+		    $range_end = $first + $ml - 1;
+                }
 
 		if ($range_end > $matches) {
 			$range_end = $matches;
@@ -99,8 +105,13 @@ sub {
 	$link_prefix = (exists $opt->{link_prefix}) ? $opt->{link_prefix} : '<li>';
 	$link_suffix = (exists $opt->{link_suffix}) ? $opt->{link_suffix} : '</li>';
 
-	$first = $q->{mv_first_match} || 0;
-	$Scratch->{paging_first_match} = $first;
+	# $first = $q->{mv_first_match} || 0;
+        if ($first > 1) {
+	    $Scratch->{paging_first_match} = $first + 1;
+        }
+        else {
+	    $Scratch->{paging_first_match} = $first;
+        }
 
 	$session = $q->{mv_cache_key};
 



More information about the wellwell-devel mailing list