diff --git a/qutebrowser/browser/navigate.py b/qutebrowser/browser/navigate.py index bffbf6fb8..194246344 100644 --- a/qutebrowser/browser/navigate.py +++ b/qutebrowser/browser/navigate.py @@ -132,6 +132,7 @@ def path_up(url, count): url: The current url. count: The number of levels to go up in the url. """ + urlutils.ensure_valid(url) url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery) path = url.path() if not path or path == '/': @@ -147,6 +148,7 @@ def strip(url, count): """Strip fragment/query from a URL.""" if count != 1: raise Error("Count is not supported when stripping URL components") + urlutils.ensure_valid(url) return url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery) diff --git a/tests/unit/browser/test_navigate.py b/tests/unit/browser/test_navigate.py index 40f7a4673..5fe0acbf6 100644 --- a/tests/unit/browser/test_navigate.py +++ b/tests/unit/browser/test_navigate.py @@ -172,7 +172,7 @@ class TestIncDec: def test_invalid_url(self): with pytest.raises(urlutils.InvalidUrlError): - navigate.incdec(QUrl(""), 1, "increment") + navigate.incdec(QUrl(), 1, "increment") def test_wrong_mode(self): """Test if incdec rejects a wrong parameter for inc_or_dec.""" @@ -196,6 +196,10 @@ class TestUp: new = navigate.path_up(url, count) assert new == QUrl(url_base + expected_suffix) + def test_invalid_url(self): + with pytest.raises(urlutils.InvalidUrlError): + navigate.path_up(QUrl(), count=1) + class TestStrip: @@ -216,3 +220,7 @@ class TestStrip: def test_count(self): with pytest.raises(navigate.Error, match='Count is not supported'): navigate.strip(QUrl('https://example.com/'), count=2) + + def test_invalid_url(self): + with pytest.raises(urlutils.InvalidUrlError): + navigate.strip(QUrl(), count=1)