From c88883fcb3f9454ddb19ccefe4270477ce232fb1 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Thu, 12 May 2016 18:21:13 +0300 Subject: [PATCH 1/3] Decode URL in statusbar when hovering over it --- qutebrowser/mainwindow/statusbar/url.py | 4 ++-- tests/unit/mainwindow/statusbar/test_url.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index e4812b384..67e0eac3e 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,7 @@ class UrlText(textbase.TextBase): _text: The text of the hovered link (string) """ if link: - self._hover_url = link + self._hover_url = QUrl(link).toString() 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..3e352a910 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,19 @@ 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'), +]) +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), From 224c877fec308d1ad1753886f575b7a932c66b87 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Sun, 15 May 2016 19:07:10 +0300 Subject: [PATCH 2/3] Hide passwords in hovering URLs --- qutebrowser/mainwindow/statusbar/url.py | 2 +- tests/unit/mainwindow/statusbar/test_url.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index 67e0eac3e..b6c9cd028 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -153,7 +153,7 @@ class UrlText(textbase.TextBase): _text: The text of the hovered link (string) """ if link: - self._hover_url = QUrl(link).toString() + self._hover_url = QUrl(link).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 3e352a910..b4397f999 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -94,6 +94,7 @@ 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') ]) def test_set_hover_url_encoded(url_widget, url_text, expected): """Test text when hovering over a percent encoded link.""" From 959f777f924df141932c333b0fa6bdd5871da009 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Tue, 17 May 2016 10:28:33 +0300 Subject: [PATCH 3/3] Assert that hovered link generates a valid QUrl --- qutebrowser/mainwindow/statusbar/url.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index b6c9cd028..6c01b8cfe 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -153,7 +153,12 @@ class UrlText(textbase.TextBase): _text: The text of the hovered link (string) """ if link: - self._hover_url = QUrl(link).toDisplayString() + # 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()