Add force_encoding call to sanitize_filename.

So that callers don't have to call both.
This commit is contained in:
Jimmy 2018-06-26 15:38:01 +12:00
parent d31fa5229d
commit ffd6ffef45
2 changed files with 7 additions and 3 deletions

View File

@ -135,11 +135,11 @@ def create_full_filename(basename, filename):
The full absolute path, or None if filename creation was not possible.
"""
basename = utils.sanitize_filename(basename)
# Filename can be a full path so don't use sanitize_filename on it.
# Remove chars which can't be encoded in the filename encoding.
# See https://github.com/qutebrowser/qutebrowser/issues/427
encoding = sys.getfilesystemencoding()
filename = utils.force_encoding(filename, encoding)
basename = utils.force_encoding(basename, encoding)
if os.path.isabs(filename) and (os.path.isdir(filename) or
filename.endswith(os.sep)):
# We got an absolute directory from the user, so we save it under
@ -161,8 +161,6 @@ def get_filename_question(*, suggested_filename, url, parent=None):
parent: The parent of the question (a QObject).
"""
suggested_filename = utils.sanitize_filename(suggested_filename)
encoding = sys.getfilesystemencoding()
suggested_filename = utils.force_encoding(suggested_filename, encoding)
q = usertypes.Question(parent)
q.title = "Save file to:"

View File

@ -499,6 +499,12 @@ def sanitize_filename(name, replacement='_'):
"""
if replacement is None:
replacement = ''
# Remove chars which can't be encoded in the filename encoding.
# See https://github.com/qutebrowser/qutebrowser/issues/427
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