diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index fbf3fe914..88499c412 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -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') diff --git a/tests/end2end/data/downloads/download with no title.html b/tests/end2end/data/downloads/download with no title.html new file mode 100644 index 000000000..da4352e59 --- /dev/null +++ b/tests/end2end/data/downloads/download with no title.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/end2end/data/downloads/qutebrowser.png b/tests/end2end/data/downloads/qutebrowser.png new file mode 100644 index 000000000..e8bbb6b56 Binary files /dev/null and b/tests/end2end/data/downloads/qutebrowser.png differ diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 8a9e8c134..40333aee6 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -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