Skip to content
Snippets Groups Projects
Verified Commit 8202dac7 authored by Mattia Rizzolo's avatar Mattia Rizzolo
Browse files

comparators/utils/file: fix handling of filesnames with non-unicode chars


Closes: #898022
Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parent 45bcf708
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,9 @@ class File(object, metaclass=abc.ABCMeta):
if not hasattr(self, '_mimedb'):
self._mimedb = magic.open(magic.NONE)
self._mimedb.load()
return self._mimedb.file(path)
return self._mimedb.file(
path.encode('utf-8', errors='surrogateescape')
)
@classmethod
def guess_encoding(self, path):
......
......@@ -143,3 +143,19 @@ def test_profiling(capsys):
assert ret == 0
assert "Profiling output for" in out
assert err == ''
def test_non_unicode_filename(capsys, tmpdir):
# Bug reference: https://bugs.debian.org/898022
path = str(tmpdir.dirpath()).encode('utf-8')
a = os.path.join(path, b'\xf0\x28\x8c\x28')
b = os.path.join(path, b'\xf0\x28\x8c\x29')
with open(a, 'w'), open(b, 'w'):
pass
# sys.argv does pretty much this decoding to arguments
files = [x.decode('utf-8', errors='surrogateescape') for x in (a, b)]
ret, out, err = run(capsys, *files)
assert ret == 0
assert out == err == ''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment