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.
This commit is contained in:
Kumi 2024-08-18 07:12:37 +02:00
parent 301cf90778
commit 6cc25796a2
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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"]