diff --git a/app/utils/bangs.py b/app/utils/bangs.py index 8661850..b9aebee 100644 --- a/app/utils/bangs.py +++ b/app/utils/bangs.py @@ -55,9 +55,10 @@ def resolve_bang(query: str, bangs_dict: dict) -> str: query = query.lower() split_query = query.split(' ') for operator in bangs_dict.keys(): - if operator not in split_query: + if operator not in split_query \ + and operator[1:] + operator[0] not in split_query: continue - return bangs_dict[operator]['url'].format( - query.replace(operator, '').strip()) + query.replace(operator if operator in split_query + else operator[1:] + operator[0], '').strip()) return '' diff --git a/test/test_routes.py b/test/test_routes.py index efd1c58..4aaaf68 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') + # Move '!' to end of the bang + rv = client.get('/search?q=gitlab%20w!') + assert rv._status_code == 302 + assert rv.headers.get('Location').startswith('https://en.wikipedia.org') + # Ensure bang is case insensitive rv = client.get('/search?q=!GH%20whoogle') assert rv._status_code == 302