From f12b0e62c571e9b4e42292af28e97ae56254fe91 Mon Sep 17 00:00:00 2001 From: BlissOWL <87573965+BlissOwl@users.noreply.github.com> Date: Tue, 28 Sep 2021 07:09:58 +0530 Subject: [PATCH] Make bang searches case insensitive (#438) Bang searches now ignore the capitalization of the operator Co-authored-by: Ben Busby --- app/utils/bangs.py | 2 ++ test/test_routes.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/utils/bangs.py b/app/utils/bangs.py index 56daf4f..8661850 100644 --- a/app/utils/bangs.py +++ b/app/utils/bangs.py @@ -51,6 +51,8 @@ def resolve_bang(query: str, bangs_dict: dict) -> str: wasn't a match or didn't contain a bang operator """ + # Ensure bang search is case insensitive + query = query.lower() split_query = query.split(' ') for operator in bangs_dict.keys(): if operator not in split_query: diff --git a/test/test_routes.py b/test/test_routes.py index 12cdda3..b894c75 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -36,6 +36,11 @@ def test_ddg_bang(client): assert rv._status_code == 302 assert rv.headers.get('Location').startswith('https://www.reddit.com') + # Ensure bang is case insensitive + rv = client.get('/search?q=!GH%20whoogle') + assert rv._status_code == 302 + assert rv.headers.get('Location').startswith('https://github.com') + def test_config(client): rv = client.post('/config', data=demo_config)