parent
a7d6cc6509
commit
3da21a32d2
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user