Skip to content

Commit

Permalink
Ignoring non ints for addon_type in list api.
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Mar 19, 2010
1 parent 6bd85c4 commit 6b4183a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 8 additions & 1 deletion apps/api/tests.py
Expand Up @@ -26,7 +26,7 @@ class No500ErrorsTest(TestCase):
"""
A series of unfortunate urls that have caused 500 errors in the past.
"""
def test_bad_type(self):
def test_search_bad_type(self):
"""
For search/:term/:addon_type <-- addon_type should be an integer.
"""
Expand All @@ -35,6 +35,13 @@ def test_bad_type(self):
# is good. We just don't want 500 errors.
assert response.status_code != 500, "We recieved a 500 error, wtf?"

def test_list_bad_type(self):
"""
For list/new/:addon_type <-- addon_type should be an integer.
"""
response = make_call('/list/new/extension')
assert response.status_code != 500, "We recieved a 500 error, wtf?"

def test_utf_redirect(self):
"""Test that urls with unicode redirect propperly."""
response = make_call(u'search/ツールバー', version=1.5)
Expand Down
13 changes: 9 additions & 4 deletions apps/api/views.py
Expand Up @@ -184,10 +184,15 @@ def process_request(self, list_type='recommended', addon_type='ALL',
else:
qs = Addon.objects.featured(self.request.APP)

if addon_type.lower() != 'all':
addon_type = int(addon_type)
if addon_type:
qs = qs.filter(type=addon_type)
if addon_type.upper() != 'ALL':
try:
addon_type = int(addon_type)
if addon_type:
qs = qs.filter(type=addon_type)

except ValueError:
# `addon_type` is ALL or a type id. Otherwise we ignore it.
pass

if platform.lower() != 'all':
qs = (qs.distinct() &
Expand Down

0 comments on commit 6b4183a

Please sign in to comment.