← Back to team overview

duplicity-team team mailing list archive

[Merge] lp:~aaron-whitehouse/duplicity/08-uexc-fix into lp:duplicity

 

Aaron Whitehouse has proposed merging lp:~aaron-whitehouse/duplicity/08-uexc-fix into lp:duplicity.

Commit message:
Fix for Bug #1770929 with associated test cases (thanks to Pete Zaitcev (zaitcev) in Bug #1797928 for the head start).

Requested reviews:
  duplicity-team (duplicity-team)
Related bugs:
  Bug #1770929 in Duplicity: "Duplicity fails with UnicodeDecodeError in uexc function"
  https://bugs.launchpad.net/duplicity/+bug/1770929

For more details, see:
https://code.launchpad.net/~aaron-whitehouse/duplicity/08-uexc-fix/+merge/364217
-- 
Your team duplicity-team is requested to review the proposed merge of lp:~aaron-whitehouse/duplicity/08-uexc-fix into lp:duplicity.
=== modified file 'duplicity/util.py'
--- duplicity/util.py	2018-11-29 19:00:15 +0000
+++ duplicity/util.py	2019-03-10 23:02:34 +0000
@@ -105,11 +105,21 @@
 
 
 def uexc(e):
+    u"""Returns the exception message in Unicode"""
     # Exceptions in duplicity often have path names in them, which if they are
     # non-ascii will cause a UnicodeDecodeError when implicitly decoding to
     # unicode.  So we decode manually, using the filesystem encoding.
     # 99.99% of the time, this will be a fine encoding to use.
-    return fsdecode(str(e).encode(u'utf-8'))
+    if e.args:
+        m = e.args[0]  # exception.message is deprecated, but this is equivalent
+        if isinstance(m, str):
+            # Already unicode
+            return m
+        else:
+            # Encoded, likely in filesystem encoding
+            return fsdecode(m)
+    else:
+        return None
 
 
 def maybe_ignore_errors(fn):

=== added file 'testing/unit/test_util.py'
--- testing/unit/test_util.py	1970-01-01 00:00:00 +0000
+++ testing/unit/test_util.py	2019-03-10 23:02:34 +0000
@@ -0,0 +1,41 @@
+#
+# This file is part of duplicity.
+#
+# Duplicity is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# Duplicity is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with duplicity; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import unittest
+import duplicity
+
+class TestExc(unittest.TestCase):
+
+    def test_uexc(self):
+
+        e = Exception('test')
+        msg = duplicity.util.uexc(e)
+        self.assertEqual(msg, 'test')
+
+        # Test for Bug #1770929
+        # https://bugs.launchpad.net/duplicity/+bug/1770929
+        e = Exception(b'\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88')
+        msg = duplicity.util.uexc(e)
+        self.assertEqual(msg, u'\u30c6\u30b9\u30c8')
+
+        e = Exception(u'\u30c6\u30b9\u30c8')
+        msg = duplicity.util.uexc(e)
+        self.assertEqual(msg, u'\u30c6\u30b9\u30c8')
+
+
+if __name__ == '__main__':
+    unittest.main()


Follow ups