Use a proper file:// URL for dirbrowser icons.
This commit is contained in:
parent
97a9255400
commit
d94c1736db
@ -25,6 +25,8 @@
|
||||
|
||||
import os
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
from qutebrowser.browser.network import schemehandler, networkreply
|
||||
from qutebrowser.utils import utils, jinja
|
||||
|
||||
@ -77,6 +79,9 @@ def dirbrowser_html(path):
|
||||
folder_icon = utils.resource_filename('img/folder.svg')
|
||||
file_icon = utils.resource_filename('img/file.svg')
|
||||
|
||||
folder_url = QUrl.fromLocalFile(folder_icon).toString(QUrl.FullyEncoded)
|
||||
file_url = QUrl.fromLocalFile(file_icon).toString(QUrl.FullyEncoded)
|
||||
|
||||
if is_root(path):
|
||||
parent = None
|
||||
else:
|
||||
@ -96,8 +101,8 @@ def dirbrowser_html(path):
|
||||
directories = get_file_list(path, all_files, os.path.isdir)
|
||||
html = template.render(title=title, url=path, icon='',
|
||||
parent=parent, files=files,
|
||||
directories=directories, folder_icon=folder_icon,
|
||||
file_icon=file_icon)
|
||||
directories=directories, folder_url=folder_url,
|
||||
file_url=file_url)
|
||||
return html.encode('UTF-8', errors='xmlcharrefreplace')
|
||||
|
||||
|
||||
|
@ -32,11 +32,11 @@ ul > li {
|
||||
}
|
||||
|
||||
ul > li {
|
||||
background-image: url('{{folder_icon}}');
|
||||
background-image: url('{{folder_url}}');
|
||||
}
|
||||
|
||||
ul.files > li {
|
||||
background-image: url('{{file_icon}}');
|
||||
background-image: url('{{file_url}}');
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -117,6 +117,19 @@ class TestDirbrowserHtml:
|
||||
title_text = title_elem('p', id='dirbrowserTitleText')[0].text
|
||||
assert title_text == 'Browse directory: {}'.format(os.getcwd())
|
||||
|
||||
def test_icons(self, monkeypatch):
|
||||
"""Make sure icon paths are correct file:// URLs."""
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.browser.network.filescheme.utils.resource_filename',
|
||||
lambda name: '/test path/foo.svg')
|
||||
|
||||
html = filescheme.dirbrowser_html(os.getcwd())
|
||||
soup = bs4.BeautifulSoup(html, 'html.parser')
|
||||
print(soup.prettify())
|
||||
|
||||
css = soup.html.head.style.string
|
||||
assert "background-image: url('file:///test%20path/foo.svg');" in css
|
||||
|
||||
def test_empty(self, tmpdir, parser):
|
||||
parsed = parser(str(tmpdir))
|
||||
assert parsed.parent
|
||||
|
Loading…
Reference in New Issue
Block a user