Commit 8202dac7 authored by Mattia Rizzolo's avatar Mattia Rizzolo

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

Closes: #898022
Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <>
parent 45bcf708
......@@ -68,7 +68,9 @@ class File(object, metaclass=abc.ABCMeta):
if not hasattr(self, '_mimedb'):
self._mimedb =
return self._mimedb.file(path)
return self._mimedb.file(
path.encode('utf-8', errors='surrogateescape')
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:
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'):
# 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 == ''
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment