Skip to content

Commit

Permalink
Merge branch '550046-bad-chars'
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Apr 9, 2010
2 parents 546278c + 5cf2018 commit f28f77f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/search/client.py
Expand Up @@ -29,6 +29,9 @@ def get_category_id(category, application):
if len(category):
return category[0].id

def sanitize_query(term):
term = term.strip('^$ ')
return term

def extract_from_query(term, filter, regexp, options={}):
"""
Expand Down Expand Up @@ -227,6 +230,7 @@ def query(self, term, limit=10, offset=0, **kwargs):
# * Logging

try:
term = sanitize_query(term)
result = sc.Query(term)
except socket.timeout:
log.error("Query has timed out.")
Expand Down
11 changes: 11 additions & 0 deletions apps/search/tests.py
Expand Up @@ -223,6 +223,17 @@ def test_status_filter(self):
eq_(query("MozEx",
status=[amo.STATUS_PUBLIC, amo.STATUS_SANDBOX])[0].id, 40)

def test_badchars(self):
""" Sphinx doesn't like queries that are entirely '$', '^' or '^ $' """
bad_guys = ('^', '$', '$ ^', '^ s $', '$s^', ' $ s ^', ' ^ s $',
'^$', '^ $')

for guy in bad_guys:
try:
query(guy)
except SearchError:
assert False, "Error querying for %s" % guy


class TestSearchForm(test_utils.TestCase):
fixtures = ['base/addons']
Expand Down

0 comments on commit f28f77f

Please sign in to comment.