From 69f845a0475791f2bf8be55a73873bf28b740aa5 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Tue, 1 Mar 2022 12:13:40 -0700 Subject: [PATCH] Add test for empty bang behavior Also fix pep8 issue --- app/utils/bangs.py | 3 ++- test/test_routes.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/utils/bangs.py b/app/utils/bangs.py index 538254a..2650658 100644 --- a/app/utils/bangs.py +++ b/app/utils/bangs.py @@ -61,7 +61,8 @@ def resolve_bang(query: str, bangs_dict: dict, fallback: str) -> str: continue bang_query = query.replace( - operator if operator in split_query else operator[1:] + operator[0], '' + operator if operator in split_query else operator[1:] + + operator[0], '' ).strip() if bang_query: diff --git a/test/test_routes.py b/test/test_routes.py index e71e995..817a555 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -47,6 +47,11 @@ def test_ddg_bang(client): assert rv._status_code == 302 assert rv.headers.get('Location').startswith('https://github.com') + # Ensure bang without content doesn't redirect to the result + rv = client.get(f'/{Endpoint.search}?q=!gh') + assert rv._status_code == 302 + assert not rv.headers.get('Location').startswith('https://github.com') + def test_config(client): rv = client.post(f'/{Endpoint.config}', data=demo_config)