changeset 9495:b2d65ee49a72

ui: guard against UnicodeDecodeErrors in ui.wrap
author Martin Geisler <mg@lazybytes.net>
date Tue, 29 Sep 2009 01:08:18 +0200
parents 44758742ad2e
children 28b089ae4001 2299c421a98e
files mercurial/util.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Sun Sep 27 01:44:46 2009 +0200
+++ b/mercurial/util.py	Tue Sep 29 01:08:18 2009 +0200
@@ -1278,9 +1278,12 @@
     padding = '\n' + ' ' * hangindent
     # To avoid corrupting multi-byte characters in line, we must wrap
     # a Unicode string instead of a bytestring.
-    u = line.decode(encoding.encoding)
-    w = padding.join(textwrap.wrap(u, width=width - hangindent))
-    return w.encode(encoding.encoding)
+    try:
+        u = line.decode(encoding.encoding)
+        w = padding.join(textwrap.wrap(u, width=width - hangindent))
+        return w.encode(encoding.encoding)
+    except UnicodeDecodeError:
+        return padding.join(textwrap.wrap(line, width=width - hangindent))
 
 def iterlines(iterator):
     for chunk in iterator: