Use page title only for whitelisted extensions
This commit is contained in:
parent
0a09758be1
commit
57e4d4978b
@ -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')
|
||||
|
8
tests/end2end/data/downloads/download with no title.html
Normal file
8
tests/end2end/data/downloads/download with no title.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
BIN
tests/end2end/data/downloads/qutebrowser.png
Normal file
BIN
tests/end2end/data/downloads/qutebrowser.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user