You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/02/10 22:44:35 UTC

[allura] 04/41: Misc: avoid errors when invalid page param

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8349
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 02657c5591d9b0aa4182dcfe803cc43144b776f1
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Feb 10 11:51:53 2020 -0500

    Misc: avoid errors when invalid page param
---
 Allura/allura/lib/app_globals.py    | 5 ++++-
 Allura/allura/tests/test_globals.py | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 05e284f..b16190a 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -383,7 +383,10 @@ class Globals(object):
         limit = self.manage_paging_preference(limit, default)
         limit = max(int(limit), 1)
         limit = min(limit, asint(config.get('limit_param_max', 500)))
-        page = max(int(page), 0)
+        try:
+            page = max(int(page), 0)
+        except ValueError:
+            page = 0
         start = page * int(limit)
         return (limit, page, start)
 
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 6e3a702..335f71d 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -912,6 +912,9 @@ class TestHandlePaging(unittest.TestCase):
         c.user.set_pref('results_per_page', 'bar')
         self.assertEqual(g.handle_paging(None, 0, 30), (30, 0, 0))
 
+    def test_with_invalid_page(self):
+        self.assertEqual(g.handle_paging(10, 'asdf', 30), (10, 0, 0))
+
 
 class TestIconRender(object):