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()
|
||||
name = force_encoding(name, encoding)
|
||||
|
||||
# Bad characters taken from Windows, there are even fewer on Linux
|
||||
# See also
|
||||
# https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
bad_chars = '\\/:*?"<>|'
|
||||
if is_windows:
|
||||
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:
|
||||
name = name.replace(bad_char, replacement)
|
||||
return name
|
||||
|
@ -22,6 +22,14 @@ import pytest
|
||||
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,
|
||||
fake_args):
|
||||
"""Simple check for download model internals."""
|
||||
@ -98,11 +106,14 @@ class TestDownloadTarget:
|
||||
assert isinstance(obj, downloads._DownloadTarget)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('raw, expected', [
|
||||
('http://foo/bar', 'bar'),
|
||||
('A *|<>\\: bear!', 'A ______ bear!')
|
||||
@pytest.mark.parametrize('raw, platform, expected', [
|
||||
('http://foo/bar', 'windows', 'bar'),
|
||||
('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()
|
||||
target = downloads.FileDownloadTarget(str(download_tmpdir))
|
||||
item = downloads.AbstractDownloadItem()
|
||||
|
Loading…
Reference in New Issue
Block a user