From 0fa34326fe140584648e0c72dfe704603460f686 Mon Sep 17 00:00:00 2001 From: Tanay Gavankar Date: Mon, 16 May 2011 19:47:09 -0400 Subject: [PATCH] [bug 655146] Make sure ints that would cause an overflow result in fallback. --- apps/sumo/tests/test__utils.py | 4 ++++ apps/sumo/utils.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/sumo/tests/test__utils.py b/apps/sumo/tests/test__utils.py index 47945c9c2c1..10f13ce8877 100644 --- a/apps/sumo/tests/test__utils.py +++ b/apps/sumo/tests/test__utils.py @@ -24,6 +24,10 @@ def test_wrong_type(self): eq_(0, smart_int(None)) eq_(10, smart_int([], 10)) + def test_large_values(self): + """Makes sure ints that would cause an overflow result in fallback.""" + eq_(0, smart_int('1' * 1000)) + class GetNextUrlTests(TestCase): def setUp(self): diff --git a/apps/sumo/utils.py b/apps/sumo/utils.py index edc99bec5b9..00ebc6a4a9d 100644 --- a/apps/sumo/utils.py +++ b/apps/sumo/utils.py @@ -55,7 +55,7 @@ def smart_int(string, fallback=0): """Convert a string to int, with fallback for invalid strings or types.""" try: return int(float(string)) - except (ValueError, TypeError): + except (ValueError, TypeError, OverflowError): return fallback