qutescheme: Improve handling of invalid path -> host redirects

This commit is contained in:
Florian Bruhin 2025-10-02 09:07:15 +02:00
parent 4aa807032f
commit 2ae3086244
2 changed files with 4 additions and 3 deletions

View File

@ -132,8 +132,9 @@ def data_for_url(url: QUrl) -> tuple[str, bytes]:
new_url = QUrl(url)
new_url.setHost(path)
new_url.setPath('/')
if new_url.host(): # path was a valid host
raise Redirect(new_url)
if not new_url.host(): # Valid path but not valid host
raise UrlInvalidError(f"Invalid host (from path): {path!r}")
raise Redirect(new_url)
if not path:
# Redirect qute://help -> qute://help/

View File

@ -42,7 +42,7 @@ class TestDataForUrl:
def test_invalid_redirect(self) -> None:
url = QUrl("qute:-")
with pytest.raises(
qutescheme.NotFoundError, match="No handler found for qute:-"
qutescheme.UrlInvalidError, match=r"Invalid host \(from path\): '-'"
):
qutescheme.data_for_url(url)