downloads: fix filename for data: links
Issue #1214 Now uses a sensible filename for data: links instead of the whole base64 content. For PDF.js, it even uses the correct pdf filename. TODO: Produces "QPainter:🔚 Painter ended with 2 saved states" while running the tests here (Arch Linux): CPython: 3.5.1 Qt: 5.5.1, runtime: 5.5.1 PyQt: 5.5.1
This commit is contained in:
parent
504bf6eb3b
commit
007425cf16
@ -775,7 +775,25 @@ class DownloadManager(QAbstractListModel):
|
|||||||
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
|
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
|
||||||
QNetworkRequest.AlwaysNetwork)
|
QNetworkRequest.AlwaysNetwork)
|
||||||
|
|
||||||
|
if request.url().scheme().lower() != 'data':
|
||||||
suggested_fn = urlutils.filename_from_url(request.url())
|
suggested_fn = urlutils.filename_from_url(request.url())
|
||||||
|
else:
|
||||||
|
# We might be downloading a binary blob embedded on a page or even
|
||||||
|
# generated dynamically via javascript. We try to figure out a more
|
||||||
|
# sensible name than the base64 content of the data.
|
||||||
|
origin = request.originatingObject()
|
||||||
|
try:
|
||||||
|
origin_url = origin.url()
|
||||||
|
except AttributeError:
|
||||||
|
# Raised either if origin is None or some object that doesn't
|
||||||
|
# have its own url. We're probably fine with a default fallback
|
||||||
|
# then.
|
||||||
|
suggested_fn = 'binary blob'
|
||||||
|
else:
|
||||||
|
# Use the originating URL as a base for the filename (works
|
||||||
|
# e.g. for pdf.js).
|
||||||
|
suggested_fn = urlutils.filename_from_url(origin_url)
|
||||||
|
|
||||||
if suggested_fn is None:
|
if suggested_fn is None:
|
||||||
suggested_fn = 'qutebrowser-download'
|
suggested_fn = 'qutebrowser-download'
|
||||||
|
|
||||||
|
10
tests/integration/data/downloads/issue1214.html
Normal file
10
tests/integration/data/downloads/issue1214.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Wrong filename when using data: links</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a href="data:;base64,cXV0ZWJyb3dzZXI=">download</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -34,6 +34,16 @@ Feature: Downloading things from a website.
|
|||||||
And I run :leave-mode
|
And I run :leave-mode
|
||||||
Then no crash should happen
|
Then no crash should happen
|
||||||
|
|
||||||
|
Scenario: Downloading a data: link (issue 1214)
|
||||||
|
When I set completion -> download-path-suggestion to filename
|
||||||
|
And I set storage -> prompt-download-directory to true
|
||||||
|
And I open data/downloads/issue1214.html
|
||||||
|
And I run :hint links download
|
||||||
|
And I run :follow-hint a
|
||||||
|
And I wait for "Asking question <qutebrowser.utils.usertypes.Question default='binary blob' mode=<PromptMode.text: 2> text='Save file to:'>, *" in the log
|
||||||
|
And I run :leave-mode
|
||||||
|
Then no crash should happen
|
||||||
|
|
||||||
Scenario: Retrying a failed download
|
Scenario: Retrying a failed download
|
||||||
When I run :download http://localhost:(port)/does-not-exist
|
When I run :download http://localhost:(port)/does-not-exist
|
||||||
And I wait for the error "Download error: * - server replied: NOT FOUND"
|
And I wait for the error "Download error: * - server replied: NOT FOUND"
|
||||||
|
@ -290,6 +290,18 @@ Feature: Various utility commands.
|
|||||||
And I open data/misc/test.pdf
|
And I open data/misc/test.pdf
|
||||||
Then "Download finished" should be logged
|
Then "Download finished" should be logged
|
||||||
|
|
||||||
|
Scenario: Downloading a pdf via pdf.js button (issue 1214)
|
||||||
|
Given pdfjs is available
|
||||||
|
When I set content -> enable-pdfjs to true
|
||||||
|
And I set completion -> download-path-suggestion to filename
|
||||||
|
And I set storage -> prompt-download-directory to true
|
||||||
|
And I open data/misc/test.pdf
|
||||||
|
And I wait for "[qute://pdfjs/*] PDF * (PDF.js: *)" in the log
|
||||||
|
And I run :jseval document.getElementById("download").click()
|
||||||
|
And I wait for "Asking question <qutebrowser.utils.usertypes.Question default='test.pdf' mode=<PromptMode.text: 2> text='Save file to:'>, *" in the log
|
||||||
|
And I run :leave-mode
|
||||||
|
Then no crash should happen
|
||||||
|
|
||||||
# :print
|
# :print
|
||||||
|
|
||||||
# Disabled because it causes weird segfaults and QPainter warnings in Qt...
|
# Disabled because it causes weird segfaults and QPainter warnings in Qt...
|
||||||
|
Loading…
Reference in New Issue
Block a user