Commit 924ac31d authored by Kai Willadsen's avatar Kai Willadsen

dirdiff: Fix display of encoding errors when scanning folders (#235)

The existing handling was Python 2 era. In the current code, we'll
always have a `str`-type root for our `os.listdir()` call, so the
entries will always be `str`s. This patch handles the Python 3 path
handling situation of getting surrogate escaped paths (in the case of a
bad file name vs. filesystem encoding) by just checking for a valid
re-encode and treating any failure as an encoding error.
parent 4e33e2a1
......@@ -778,11 +778,11 @@ class DirDiff(MeldDoc, Component):
for e in entries:
if not isinstance(e, str):
e = e.decode('utf8')
except UnicodeDecodeError:
approximate_name = e.decode('utf8', 'replace')
encoding_errors.append((pane, approximate_name))
except UnicodeEncodeError:
invalid = e.encode('utf8', 'surrogatepass')
printable = invalid.decode('utf8', 'backslashreplace')
encoding_errors.append((pane, printable))
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