# HG changeset patch
# User Sune Foldager <c...@cyanite.org>
# Date 1257940776 -3600
# Branch stable
# Node ID 4366d06668022991d05105433cb986224bcf9d4b
# Parent  ecf1189f9fab6f166b735d50808f40ef23adf6b2
fix 80-char limiting of utf-8 encoded strings

The limit was applied to the native encoded string, which not only calculates 
the wrong
length but also makes GTK crash badly if a code point is cut in half, when the 
native
encoding was UTF-8.

diff --git a/tortoisehg/hgtk/changeset.py b/tortoisehg/hgtk/changeset.py
--- a/tortoisehg/hgtk/changeset.py
+++ b/tortoisehg/hgtk/changeset.py
@@ -447,8 +447,8 @@
             return gtklib.markup(revid, **opts)
         def data_func(widget, item, ctx):
             def summary_line(desc):
-                desc = desc.replace('\0', '')
-                return hglib.toutf(desc.split('\n')[0][:80])
+                desc = hglib.tounicode(desc.replace('\0', '').split('\n')[0])
+                return hglib.toutf(desc[:80])
             def revline_data(ctx, hl=False, branch=None):
                 if isinstance(ctx, basestring):
                     return ctx
diff --git a/tortoisehg/hgtk/csinfo.py b/tortoisehg/hgtk/csinfo.py
--- a/tortoisehg/hgtk/csinfo.py
+++ b/tortoisehg/hgtk/csinfo.py
@@ -220,11 +220,11 @@
             elif item == 'desc':
                 return hglib.toutf(ctx.description().replace('\0', ''))
             elif item == 'summary':
-                desc = self.get_data('desc', *args)
-                value = desc.split('\n')[0][:80]
+                value = ctx.description().replace('\0', '').split('\n')[0]
+                value = hglib.tounicode(value[:80])
                 if len(value) == 0:
                     return  None
-                return value
+                return hglib.toutf(value)
             elif item == 'user':
                 return hglib.toutf(ctx.user())
             elif item == 'dateage':
diff --git a/tortoisehg/hgtk/hgcmd.py b/tortoisehg/hgtk/hgcmd.py
--- a/tortoisehg/hgtk/hgcmd.py
+++ b/tortoisehg/hgtk/hgcmd.py
@@ -28,7 +28,7 @@
             self.cmdlist = []
         title = text or ' '.join(cmdline)
         if len(title) > 80:
-            title = title[:80] + '...'
+            title = hglib.tounicode(title)[:80] + '...'
         title = hglib.toutf(title.replace('\n', ' '))
         gtk.Dialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL)
         self.set_has_separator(False)

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to