Skip to content

Commit

Permalink
strip spaces from start/end of search term
Browse files Browse the repository at this point in the history
Fixes #477
  • Loading branch information
struan committed Feb 21, 2024
1 parent 085795d commit 6ac093f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hub/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ def test_area_name_lookup(self):
context = response.context
self.assertEqual(context["area"].name, "South Borsetshire")

def test_search_with_spaces(self):
url = reverse("area_search")
response = self.client.get(url, {"search": " South Borsetshire"}, follow=True)

self.assertRedirects(response, "/area/WMC/South%20Borsetshire")
self.assertTemplateUsed(response, "hub/area.html")

response = self.client.get(url, {"search": "South Borsetshire "}, follow=True)

self.assertRedirects(response, "/area/WMC/South%20Borsetshire")
self.assertTemplateUsed(response, "hub/area.html")

context = response.context
self.assertEqual(context["area"].name, "South Borsetshire")

def test_mp_name_lookup(self):
url = reverse("area_search")
response = self.client.get(url, {"search": "James Madeupname"}, follow=True)
Expand Down
3 changes: 3 additions & 0 deletions hub/views/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ def get_context_data(self, **kwargs):
if search is None and lat is None and lon is None:
return context

if search is not None:
search = search.strip()

context["search"] = search

if lon and lat:
Expand Down

0 comments on commit 6ac093f

Please sign in to comment.