[meld/meld-3-18] dirdiff: Fix display of encoding errors when scanning folders (#235)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/meld-3-18] dirdiff: Fix display of encoding errors when scanning folders (#235)
- Date: Sat, 27 Oct 2018 23:02:09 +0000 (UTC)
commit 347a179e730d67d4d49f72e28de8c08b96344546
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Oct 28 08:54:46 2018 +1000
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.
meld/dirdiff.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index b26acae4..ac1803b8 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -716,11 +716,11 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
for e in entries:
try:
- if not isinstance(e, str):
- e = e.decode('utf8')
- except UnicodeDecodeError:
- approximate_name = e.decode('utf8', 'replace')
- encoding_errors.append((pane, approximate_name))
+ e.encode('utf8')
+ except UnicodeEncodeError:
+ invalid = e.encode('utf8', 'surrogatepass')
+ printable = invalid.decode('utf8', 'backslashreplace')
+ encoding_errors.append((pane, printable))
continue
try:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]