qutescheme: Simplify URL/path normalization logic

See #8711
This commit is contained in:
Florian Bruhin 2025-10-02 09:04:17 +02:00
parent 0867a95abb
commit 4aa807032f
1 changed files with 10 additions and 12 deletions

View File

@ -123,26 +123,24 @@ def data_for_url(url: QUrl) -> tuple[str, bytes]:
path = url.path()
host = url.host()
query = url.query()
# A url like "qute:foo" is split as "scheme:path", not "scheme:host".
log.misc.debug("url: {}, path: {}, host {}".format(
url.toDisplayString(), path, host))
if not path or not host:
new_url = QUrl()
new_url.setScheme('qute')
# When path is absent, e.g. qute://help (with no trailing slash)
if host:
new_url.setHost(host)
# When host is absent, e.g. qute:help
else:
new_url.setHost(path)
if not host:
# Redirect qute:help -> qute://help/
new_url = QUrl(url)
new_url.setHost(path)
new_url.setPath('/')
if query:
new_url.setQuery(query)
if new_url.host(): # path was a valid host
raise Redirect(new_url)
if not path:
# Redirect qute://help -> qute://help/
new_url = QUrl(url)
new_url.setPath('/')
raise Redirect(new_url)
try:
handler = _HANDLERS[host]
except KeyError: