allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kentontay...@apache.org
Subject allura git commit: Error handling around invalid pagination limits
Date Fri, 12 Oct 2018 14:57:25 GMT
Repository: allura
Updated Branches:
  refs/heads/master cd8321cf1 -> 181b82e6b


Error handling around invalid pagination limits


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/181b82e6
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/181b82e6
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/181b82e6

Branch: refs/heads/master
Commit: 181b82e6b2883b5f263ba17904acf9a3904078ac
Parents: cd8321c
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Oct 12 10:40:25 2018 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Fri Oct 12 10:40:25 2018 -0400

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py    | 6 +++++-
 Allura/allura/tests/test_globals.py | 6 ++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/181b82e6/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index f9ebc03..1260ca3 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -369,7 +369,11 @@ class Globals(object):
                 limit = default
             else:
                 limit = c.user.get_pref('results_per_page') or default
-        return int(limit)
+        try:
+            limit = int(limit)
+        except ValueError:
+            limit = default
+        return limit
 
     def document_class(self, neighborhood):
         classes = ''

http://git-wip-us.apache.org/repos/asf/allura/blob/181b82e6/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index b0650a5..caf9ab4 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -800,6 +800,12 @@ class TestHandlePaging(unittest.TestCase):
         # handle paging must not mess up user preferences
         self.assertEqual(c.user.get_pref('results_per_page'), 25)
 
+    def test_with_invalid_limit(self):
+        self.assertEqual(g.handle_paging('foo', 0, 30), (30, 0, 0))
+
+        c.user.set_pref('results_per_page', 'bar')
+        self.assertEqual(g.handle_paging(None, 0, 30), (30, 0, 0))
+
 
 class TestIconRender(object):
 


Mime
View raw message