Use page title only for whitelisted extensions

This commit is contained in:
Iordanis Grigoriou 2017-07-06 11:59:02 +02:00
parent 0a09758be1
commit 57e4d4978b
4 changed files with 33 additions and 1 deletions

View File

@ -1443,12 +1443,22 @@ class CommandDispatcher:
download_manager.get_mhtml(tab, target)
else:
qnam = tab.networkaccessmanager()
# Downloads of URLs with file extensions in the whitelist will use
# the page title as the filename.
ext_whitelist = [".html", ".htm", ".php", ""]
_, ext = os.path.splitext(self._current_url().path())
if ext.lower() in ext_whitelist and tab.title():
suggested_fn = utils.sanitize_filename(tab.title()) + ext
else:
suggested_fn = None
download_manager.get(
self._current_url(),
user_agent=user_agent,
qnam=qnam,
target=target,
suggested_fn=utils.sanitize_filename(tab.title() + ".html")
suggested_fn=suggested_fn
)
@cmdutils.register(instance='command-dispatcher', scope='window')

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -29,6 +29,20 @@ Feature: Downloading things from a website.
And I wait until the download is finished
Then the downloaded file Simple downloads.html should exist
Scenario: Using :download with no URL on an image
When I set storage -> prompt-download-directory to false
And I open data/downloads/qutebrowser.png
And I run :download
And I wait until the download is finished
Then the downloaded file qutebrowser.png should exist
Scenario: Using :download with no URL and no page title
When I set storage -> prompt-download-directory to false
And I open data/downloads/download with no title.html
And I run :download
And I wait until the download is finished
Then the downloaded file download with no title.html should exist
Scenario: Using hints
When I set storage -> prompt-download-directory to false
And I open data/downloads/downloads.html