From 16a7e6febe53bd5e248a529d7c73746adb7db1d4 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Wed, 6 May 2009 18:34:39 +0000
Subject: [PATCH] do not raise an exception if a user input negative value or
 non-number string as a page number.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26862 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/SelectionTool.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/product/ERP5Form/SelectionTool.py b/product/ERP5Form/SelectionTool.py
index 1f2366e596..37994b5d4c 100644
--- a/product/ERP5Form/SelectionTool.py
+++ b/product/ERP5Form/SelectionTool.py
@@ -677,10 +677,13 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
         lines = int(params.get('list_lines', 0))
         form = REQUEST.form
         if form.has_key('page_start'):
-          list_start = (int(form.pop('page_start', 0)) - 1) * lines
+          try:
+            list_start = (int(form.pop('page_start', 0)) - 1) * lines
+          except ValueError:
+            list_start = 0
         else:
           list_start = int(form.pop('list_start', 0))
-        params['list_start'] = list_start + lines
+        params['list_start'] = max(list_start + lines, 0)
         selection.edit(params=params)
       self.uncheckAll(list_selection_name, listbox_uid)
       return self.checkAll(list_selection_name, uids, REQUEST=REQUEST)
@@ -697,7 +700,10 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
         lines = int(params.get('list_lines', 0))
         form = REQUEST.form
         if form.has_key('page_start'):
-          list_start = (int(form.pop('page_start', 0)) - 1) * lines
+          try:
+            list_start = (int(form.pop('page_start', 0)) - 1) * lines
+          except ValueError:
+            list_start = 0
         else:
           list_start = int(form.pop('list_start', 0))
         params['list_start'] = max(list_start - lines, 0)
@@ -717,10 +723,13 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
         lines = int(params.get('list_lines', 0))
         form = REQUEST.form
         if form.has_key('page_start'):
-          list_start = (int(form.pop('page_start', 0)) - 1) * lines
+          try:
+            list_start = (int(form.pop('page_start', 0)) - 1) * lines
+          except ValueError:
+            list_start = 0
         else:
           list_start = int(form.pop('list_start', 0))
-        params['list_start'] = list_start
+        params['list_start'] = max(list_start, 0)
         selection.edit(params=params)
         self.uncheckAll(list_selection_name, listbox_uid)
       return self.checkAll(list_selection_name, uids, REQUEST=REQUEST, query_string=query_string)
-- 
2.30.9