[pygobject] Fix Gtk.UIManager.add_ui_from_string() override for non-ASCII chars



commit 948dbcb223249a08f4398d4ad8861e92e3de0dfa
Author: Jonathan Ballet <jon multani info>
Date:   Thu Dec 27 16:04:51 2012 +0100

    Fix Gtk.UIManager.add_ui_from_string() override for non-ASCII chars
    
    The length argument is the size of the buffer in bytes, not in characters.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690329
    
    Co-Authored-By: Martin Pitt <martinpitt gnome org>

 gi/overrides/Gtk.py         |    2 +-
 tests/test_overrides_gtk.py |    7 +++++++
 2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 78bbd36..223d8f4 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -294,7 +294,7 @@ class UIManager(Gtk.UIManager):
         if not isinstance(buffer, _basestring):
             raise TypeError('buffer must be a string')
 
-        length = len(buffer)
+        length = len(buffer.encode('UTF-8'))
 
         return Gtk.UIManager.add_ui_from_string(self, buffer, length)
 
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 7ed8344..3578ef0 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1,4 +1,5 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
+# coding: UTF-8
 # vim: tabstop=4 shiftwidth=4 expandtab
 
 import unittest
@@ -114,6 +115,12 @@ class TestGtk(unittest.TestCase):
         self.assertEqual(ag, groups[-2])
         self.assertEqual(ag2, groups[-1])
 
+    def test_uimanager_nonascii(self):
+        ui = Gtk.UIManager()
+        ui.add_ui_from_string(b'<ui><menubar name="menub\xc3\xa6r1" /></ui>'.decode('UTF-8'))
+        mi = ui.get_widget("/menubÃr1")
+        self.assertEqual(type(mi), Gtk.MenuBar)
+
     def test_builder(self):
         self.assertEqual(Gtk.Builder, gi.overrides.Gtk.Builder)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]