From ddf951de35dabf1bfff65a1547caca1e41bd380c Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Mon, 1 Nov 2021 16:47:48 -0600 Subject: [PATCH] Use `replace` in bang query formatting Using `format` for formatting bang queries caused a KeyError for some searches, such as !hd (HUDOC). In that example, the URL returned in the bangs json was `http://...#{%22fulltext%22:[%22{}%22]...`, where standard formatting would not work due to the misidentification of "fulltext" as a formatting key. The logic has been updated to just replace the first occurence of "{}" in the URL returned by the bangs dict. Fixes #513 --- app/utils/bangs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils/bangs.py b/app/utils/bangs.py index b9aebee..9e71233 100644 --- a/app/utils/bangs.py +++ b/app/utils/bangs.py @@ -58,7 +58,7 @@ def resolve_bang(query: str, bangs_dict: dict) -> str: if operator not in split_query \ and operator[1:] + operator[0] not in split_query: continue - return bangs_dict[operator]['url'].format( + return bangs_dict[operator]['url'].replace('{}', query.replace(operator if operator in split_query - else operator[1:] + operator[0], '').strip()) + else operator[1:] + operator[0], '').strip(), 1) return ''