Merge branch 'forkbong-pretty-hover-url'

This commit is contained in:
Florian Bruhin 2016-05-18 07:28:39 +02:00
commit d837e3eb91
4 changed files with 23 additions and 4 deletions

View File

@ -49,6 +49,7 @@ Changed
- `:bind <key>` 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
-----

View File

@ -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

View File

@ -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()

View File

@ -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),