Merge branch 'data-link-fix' of https://github.com/Kingdread/qutebrowser into Kingdread-data-link-fix

This commit is contained in:
Florian Bruhin 2016-02-27 03:01:19 +01:00
commit c156f53eba
4 changed files with 55 additions and 1 deletions

View File

@ -775,7 +775,25 @@ class DownloadManager(QAbstractListModel):
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
QNetworkRequest.AlwaysNetwork)
suggested_fn = urlutils.filename_from_url(request.url())
if request.url().scheme().lower() != 'data':
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:
suggested_fn = 'qutebrowser-download'

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

View File

@ -34,6 +34,16 @@ Feature: Downloading things from a website.
And I run :leave-mode
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
When I run :download http://localhost:(port)/does-not-exist
And I wait for the error "Download error: * - server replied: NOT FOUND"

View File

@ -290,6 +290,22 @@ Feature: Various utility commands.
And I open data/misc/test.pdf
Then "Download finished" should be logged
Scenario: Downloading a pdf via pdf.js button (issue 1214)
Given pdfjs is available
# WORKAROUND to prevent the "Painter ended with 2 saved states" warning
# Might be related to https://bugreports.qt.io/browse/QTBUG-13524 and
# a weird interaction with the previous test.
When I wait 1s
And 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
# Disabled because it causes weird segfaults and QPainter warnings in Qt...