Makes sanitize_filenames platform dependant.
Hopefully having the posix bad_chars list so minimal won't ruin anyones day.
This commit is contained in:
parent
1febcb9fce
commit
747acfe7fa
@ -505,10 +505,16 @@ def sanitize_filename(name, replacement='_'):
|
|||||||
encoding = sys.getfilesystemencoding()
|
encoding = sys.getfilesystemencoding()
|
||||||
name = force_encoding(name, encoding)
|
name = force_encoding(name, encoding)
|
||||||
|
|
||||||
# Bad characters taken from Windows, there are even fewer on Linux
|
|
||||||
# See also
|
# See also
|
||||||
# https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
# https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||||
|
if is_windows:
|
||||||
bad_chars = '\\/:*?"<>|'
|
bad_chars = '\\/:*?"<>|'
|
||||||
|
elif is_mac:
|
||||||
|
# Colons can be confusing in finder https://superuser.com/a/326627
|
||||||
|
bad_chars = '/:'
|
||||||
|
else:
|
||||||
|
bad_chars = '/'
|
||||||
|
|
||||||
for bad_char in bad_chars:
|
for bad_char in bad_chars:
|
||||||
name = name.replace(bad_char, replacement)
|
name = name.replace(bad_char, replacement)
|
||||||
return name
|
return name
|
||||||
|
@ -22,6 +22,14 @@ import pytest
|
|||||||
from qutebrowser.browser import downloads, qtnetworkdownloads
|
from qutebrowser.browser import downloads, qtnetworkdownloads
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def is_platform(monkeypatch, platform="windows"):
|
||||||
|
for p in ["mac", "linux", "posix", "windows"]:
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'qutebrowser.utils.utils.is_{}'.format(p),
|
||||||
|
p == platform)
|
||||||
|
|
||||||
|
|
||||||
def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache,
|
def test_download_model(qapp, qtmodeltester, config_stub, cookiejar_and_cache,
|
||||||
fake_args):
|
fake_args):
|
||||||
"""Simple check for download model internals."""
|
"""Simple check for download model internals."""
|
||||||
@ -98,11 +106,14 @@ class TestDownloadTarget:
|
|||||||
assert isinstance(obj, downloads._DownloadTarget)
|
assert isinstance(obj, downloads._DownloadTarget)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('raw, expected', [
|
@pytest.mark.parametrize('raw, platform, expected', [
|
||||||
('http://foo/bar', 'bar'),
|
('http://foo/bar', 'windows', 'bar'),
|
||||||
('A *|<>\\: bear!', 'A ______ bear!')
|
('A *|<>\\: bear!', 'windows', 'A ______ bear!'),
|
||||||
|
('A *|<>\\: bear!', 'posix', 'A *|<>\\: bear!')
|
||||||
])
|
])
|
||||||
def test_sanitized_filenames(raw, expected, config_stub, download_tmpdir):
|
def test_sanitized_filenames(raw, platform, expected, config_stub,
|
||||||
|
download_tmpdir, monkeypatch):
|
||||||
|
is_platform(monkeypatch, platform)
|
||||||
manager = downloads.AbstractDownloadManager()
|
manager = downloads.AbstractDownloadManager()
|
||||||
target = downloads.FileDownloadTarget(str(download_tmpdir))
|
target = downloads.FileDownloadTarget(str(download_tmpdir))
|
||||||
item = downloads.AbstractDownloadItem()
|
item = downloads.AbstractDownloadItem()
|
||||||
|
Loading…
Reference in New Issue
Block a user