diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 35b3d26c6..e9499600e 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -182,20 +182,22 @@ def transform_path(path): return path -def suggested_fn_from_title(url, title=None): +def suggested_fn_from_title(url_path, title=None): """Suggest a filename depending on the URL extension and page title. + Args: - url: a string with the URL path + url_path: a string with the URL path title: the page title string - Returns None if the extension is not in the whitelist - or if there is no page title. + Return: + The download filename based on the title, or None if the extension is + not found in the whitelist (or if there is no page title). """ ext_whitelist = [".html", ".htm", ".php", ""] - _, ext = os.path.splitext(url) + _, ext = os.path.splitext(url_path) if ext.lower() in ext_whitelist and title: suggested_fn = utils.sanitize_filename(title) - if not suggested_fn.endswith(ext): + if not suggested_fn.lower().endswith(ext.lower()): suggested_fn += ext else: suggested_fn = None diff --git a/tests/unit/browser/webkit/test_downloads.py b/tests/unit/browser/webkit/test_downloads.py index d22338717..c9451b949 100644 --- a/tests/unit/browser/webkit/test_downloads.py +++ b/tests/unit/browser/webkit/test_downloads.py @@ -31,21 +31,27 @@ def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache): @pytest.mark.parametrize('url, title, out', [ - ('https://qutebrowser.org/img/cheatsheet-big.png', - 'cheatsheet-big.png (3342×2060)', - None), ('http://qutebrowser.org/INSTALL.html', 'Installing qutebrowser | qutebrowser', 'Installing qutebrowser _ qutebrowser.html'), - ('http://qutebrowser.org/INSTALL.html.html', - 'Installing qutebrowser | qutebrowser', + ('http://qutebrowser.org/INSTALL.html', + 'Installing qutebrowser | qutebrowser.html', 'Installing qutebrowser _ qutebrowser.html'), + ('http://qutebrowser.org/INSTALL.HTML', + 'Installing qutebrowser | qutebrowser', + 'Installing qutebrowser _ qutebrowser.HTML'), + ('http://qutebrowser.org/INSTALL.html', + 'Installing qutebrowser | qutebrowser.HTML', + 'Installing qutebrowser _ qutebrowser.HTML'), ('http://qutebrowser.org/', 'qutebrowser | qutebrowser', 'qutebrowser _ qutebrowser'), ('https://github.com/qutebrowser/qutebrowser/releases', 'Releases · qutebrowser/qutebrowser', 'Releases · qutebrowser_qutebrowser'), + ('https://qutebrowser.org/img/cheatsheet-big.png', + 'cheatsheet-big.png (3342×2060)', + None), ('http://qutebrowser.org/page-with-no-title.html', '', None),