From 6cc25796a20fc4195d6387dfbb5510203266bc22 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 18 Aug 2024 07:12:37 +0200 Subject: [PATCH] fix(search): properly escape and format search queries Refined the search URL construction to correctly escape and format the search queries by replacing spaces with underscores and escaping characters. This ensures more accurate search results and improved reliability of the search functionality. Fixes #6. --- src/wikimore/app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index c02a292..266e15b 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -205,7 +205,11 @@ def search_results(project, lang, query): logger.debug(f"Searching {base_url} for {query}") - url = f"{base_url}/w/api.php?action=query&format=json&list=search&srsearch={query}" + srquery = escape(query.replace(" ", "_"), True) + + url = ( + f"{base_url}/w/api.php?action=query&format=json&list=search&srsearch={srquery}" + ) with urllib.request.urlopen(url) as response: data = json.loads(response.read().decode()) search_results = data["query"]["search"]