diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 7cb58afbd..99fd043b9 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -49,6 +49,7 @@ Changed - `:bind ` without a command now shows the existing binding - The optional `colorlog` dependency got removed, as qutebrowser now displays colored logs without it. +- URLs are now shown decoded when hovering. Fixed ----- diff --git a/README.asciidoc b/README.asciidoc index c23b6c86b..99a5a1630 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -154,10 +154,10 @@ Contributors, sorted by the number of commits in descending order: * meles5 * Tarcisio Fedrizzi * Philipp Hansch +* Panagiotis Ktistakis * Artur Shaik * Nathan Isom * Thorsten Wißmann -* Panagiotis Ktistakis * Kevin Velghe * Austin Anderson * Jimmy diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index e4812b384..6c01b8cfe 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -19,7 +19,7 @@ """URL displayed in the statusbar.""" -from PyQt5.QtCore import pyqtSlot, pyqtProperty, Qt +from PyQt5.QtCore import pyqtSlot, pyqtProperty, Qt, QUrl from qutebrowser.browser import webview from qutebrowser.mainwindow.statusbar import textbase @@ -153,7 +153,12 @@ class UrlText(textbase.TextBase): _text: The text of the hovered link (string) """ if link: - self._hover_url = 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() 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 1d5878a01..b4397f999 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -76,7 +76,6 @@ def test_set_url(url_widget, url_text): @pytest.mark.parametrize('url_text, title, text', [ ('http://abc123.com/this/awesome/url.html', 'Awesome site', 'click me!'), ('https://supersecret.gov/nsa/files.txt', 'Secret area', None), - ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', 'Probably spam', 'definitely'), (None, None, 'did I break?!') ]) def test_set_hover_url(url_widget, url_text, title, text): @@ -90,6 +89,20 @@ def test_set_hover_url(url_widget, url_text, title, text): assert url_widget._urltype == url.UrlType.normal +@pytest.mark.parametrize('url_text, expected', [ + ('http://test.gr/%CE%B1%CE%B2%CE%B3%CE%B4.txt', 'http://test.gr/αβγδ.txt'), + ('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') +]) +def test_set_hover_url_encoded(url_widget, url_text, expected): + """Test text when hovering over a percent encoded link.""" + url_widget.set_hover_url(url_text, 'title', 'text') + assert url_widget.text() == expected + assert url_widget._urltype == url.UrlType.hover + + @pytest.mark.parametrize('status, expected', [ (webview.LoadStatus.success, url.UrlType.success), (webview.LoadStatus.success_https, url.UrlType.success_https),