treat E: and E:\ the same when downloading

Fixes #2305
This commit is contained in:
Daniel Schadt 2017-03-23 14:59:22 +01:00
parent a7d6cc6509
commit 3da21a32d2
4 changed files with 36 additions and 0 deletions

View File

@ -583,6 +583,8 @@ class AbstractDownloadItem(QObject):
"""
global last_used_directory
filename = os.path.expanduser(filename)
if sys.platform == "win32":
filename = utils.expand_windows_drive(filename)
self._ensure_can_set_filename(filename)
self._filename = create_full_filename(self.basename, filename)

View File

@ -554,6 +554,8 @@ def start_download_checked(target, tab):
dest = utils.force_encoding(target.filename, encoding)
dest = os.path.expanduser(dest)
if sys.platform == "win32":
dest = utils.expand_windows_drive(dest)
# See if we already have an absolute path
path = downloads.create_full_filename(default_name, dest)

View File

@ -20,6 +20,7 @@
"""Other utilities which don't fit anywhere else."""
import io
import re
import sys
import enum
import json
@ -845,3 +846,21 @@ def open_file(filename, cmdline=None):
def unused(_arg):
"""Function which does nothing to avoid pylint complaining."""
pass
def expand_windows_drive(path):
r"""Expand a drive-path like E: into E:\.
Does nothing for other paths.
Args:
path: The path to expand.
"""
# Usually, "E:" on Windows refers to the current working directory on drive
# E:\. The correct way to specifify drive E: is "E:\", but most users
# probably don't use the "multiple working directories" feature and expect
# "E:" and "E:\" to be equal.
if re.match(r'[A-Z]:$', path, re.IGNORECASE):
return path + "\\"
else:
return path

View File

@ -916,3 +916,16 @@ class TestOpenFile:
def test_unused():
utils.unused(None)
@pytest.mark.parametrize('path, expected', [
('E:', 'E:\\'),
('e:', 'e:\\'),
('E:foo', 'E:foo'),
('E:\\', 'E:\\'),
('E:\\foo', 'E:\\foo'),
('foo:', 'foo:'),
('foo:bar', 'foo:bar'),
])
def test_expand_windows_drive(path, expected):
assert utils.expand_windows_drive(path) == expected