changeset 9480:44758742ad2e

util: do not corrupt multi-byte characters in wrap
author Martin Geisler <mg@lazybytes.net>
date Sun, 27 Sep 2009 01:44:46 +0200
parents f3569d95c2ab
children ca3390c19f88 b2d65ee49a72
files mercurial/util.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Wed Sep 23 18:56:09 2009 +0200
+++ b/mercurial/util.py	Sun Sep 27 01:44:46 2009 +0200
@@ -14,7 +14,7 @@
 """
 
 from i18n import _
-import error, osutil
+import error, osutil, encoding
 import cStringIO, errno, re, shutil, sys, tempfile, traceback
 import os, stat, time, calendar, random, textwrap
 import imp
@@ -1276,7 +1276,11 @@
 
 def wrap(line, hangindent, width=78):
     padding = '\n' + ' ' * hangindent
-    return padding.join(textwrap.wrap(line, width=width - 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)
 
 def iterlines(iterator):
     for chunk in iterator: