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
main
Ben Busby 2021-11-01 16:47:48 -06:00
parent 829903fb9c
commit ddf951de35
No known key found for this signature in database
GPG Key ID: 339B7B7EB5333D14
1 changed files with 2 additions and 2 deletions

View File

@ -58,7 +58,7 @@ def resolve_bang(query: str, bangs_dict: dict) -> str:
if operator not in split_query \ if operator not in split_query \
and operator[1:] + operator[0] not in split_query: and operator[1:] + operator[0] not in split_query:
continue continue
return bangs_dict[operator]['url'].format( return bangs_dict[operator]['url'].replace('{}',
query.replace(operator if operator in split_query query.replace(operator if operator in split_query
else operator[1:] + operator[0], '').strip()) else operator[1:] + operator[0], '').strip(), 1)
return '' return ''