diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index 6c01b8cfe..4d8e6e2a0 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -153,12 +153,11 @@ class UrlText(textbase.TextBase): _text: The text of the hovered link (string) """ if link: - # We assume that `link` is always be given in a form that generates - # a valid QUrl. If this proves to be wrong, we should probably - # check and fall back to the text version otherwise. qurl = QUrl(link) - assert qurl.isValid(), link - self._hover_url = qurl.toDisplayString() + if qurl.isValid(): + self._hover_url = qurl.toDisplayString() + else: + self._hover_url = link else: self._hover_url = None self._update_url() diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index b4397f999..588ad2672 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -94,7 +94,8 @@ def test_set_hover_url(url_widget, url_text, title, text): ('http://test.ru/%D0%B0%D0%B1%D0%B2%D0%B3.txt', 'http://test.ru/абвг.txt'), ('http://test.com/s%20p%20a%20c%20e.txt', 'http://test.com/s p a c e.txt'), ('http://test.com/%22quotes%22.html', 'http://test.com/%22quotes%22.html'), - ('http://username:secret%20password@test.com', 'http://username@test.com') + ('http://username:secret%20password@test.com', 'http://username@test.com'), + ('http://example.com%5b/', 'http://example.com%5b/'), # invalid url ]) def test_set_hover_url_encoded(url_widget, url_text, expected): """Test text when hovering over a percent encoded link."""