Handle unknown filetypes with qute://help
This commit is contained in:
parent
9dc9bcaf39
commit
354c3c8c9b
@ -35,6 +35,7 @@ Fixed
|
||||
|
||||
- More consistent sizing for favicons with vertical tabs.
|
||||
- Using `:home` on pinned tabs is now prevented.
|
||||
- Fix crash with unknown file types loaded via qute://help
|
||||
|
||||
Deprecated
|
||||
~~~~~~~~~~
|
||||
|
@ -29,8 +29,9 @@ import os
|
||||
import time
|
||||
import urllib.parse
|
||||
import textwrap
|
||||
import pkg_resources
|
||||
import mimetypes
|
||||
|
||||
import pkg_resources
|
||||
from PyQt5.QtCore import QUrlQuery, QUrl
|
||||
|
||||
import qutebrowser
|
||||
@ -323,8 +324,10 @@ def qute_help(url):
|
||||
"scripts/asciidoc2html.py.")
|
||||
|
||||
path = 'html/doc/{}'.format(urlpath)
|
||||
if urlpath.endswith('.png'):
|
||||
return 'image/png', utils.read_file(path, binary=True)
|
||||
if not urlpath.endswith('.html'):
|
||||
mimetype, _encoding = mimetypes.guess_type(urlpath)
|
||||
assert mimetype is not None, url
|
||||
return mimetype, utils.read_file(path, binary=True)
|
||||
|
||||
try:
|
||||
data = utils.read_file(path)
|
||||
|
@ -146,3 +146,26 @@ class TestHistoryHandler:
|
||||
url = QUrl("qute://history/data?start_time={}".format(now))
|
||||
_mimetype, data = benchmark(qutescheme.qute_history, url)
|
||||
assert len(json.loads(data)) > 1
|
||||
|
||||
|
||||
class TestHelpHandler:
|
||||
|
||||
"""Tests for qute://help."""
|
||||
|
||||
@pytest.fixture
|
||||
def data_patcher(self, monkeypatch):
|
||||
def _patch(path, data):
|
||||
def _read_file(name, binary=False):
|
||||
assert path == name
|
||||
if binary:
|
||||
return data
|
||||
return data.decode('utf-8')
|
||||
|
||||
monkeypatch.setattr(qutescheme.utils, 'read_file', _read_file)
|
||||
return _patch
|
||||
|
||||
def test_unknown_file_type(self, data_patcher):
|
||||
data_patcher('html/doc/foo.bin', b'\xff')
|
||||
mimetype, data = qutescheme.qute_help(QUrl('qute://help/foo.bin'))
|
||||
assert mimetype == 'application/octet-stream'
|
||||
assert data == b'\xff'
|
||||
|
Loading…
Reference in New Issue
Block a user