Rev 5988: Properly load utf8-encoded config files in file:///home/vila/src/bzr/bugs/799212-non-ascii-confs/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Jun 20 09:31:17 UTC 2011


At file:///home/vila/src/bzr/bugs/799212-non-ascii-confs/

------------------------------------------------------------
revno: 5988
revision-id: v.ladeuil+lp at free.fr-20110620093117-8o1ytb8hoemgq710
parent: pqm at pqm.ubuntu.com-20110619183340-ds1rpql77nxrmo4n
fixes bug(s): https://launchpad.net/bugs/799212
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 799212-non-ascii-confs
timestamp: Mon 2011-06-20 11:31:17 +0200
message:
  Properly load utf8-encoded config files
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-06-19 02:48:01 +0000
+++ b/bzrlib/config.py	2011-06-20 09:31:17 +0000
@@ -2375,13 +2375,10 @@
 
         :param str_or_unicode: A string representing the file content. This will
             be utf-8 encoded internally.
-
-        This is for tests and should not be used in production unless a
-        convincing use case can be demonstrated :)
         """
         if self.is_loaded():
             raise AssertionError('Already loaded: %r' % (self._config_obj,))
-        co_input = StringIO(str_or_unicode.encode('utf-8'))
+        co_input = StringIO(str_or_unicode)
         try:
             # The config files are always stored utf8-encoded
             self._config_obj = ConfigObj(co_input, encoding='utf-8')

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-06-14 10:07:16 +0000
+++ b/bzrlib/tests/test_config.py	2011-06-20 09:31:17 +0000
@@ -2328,6 +2328,22 @@
         self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
 
 
+class TestBug799212(TestStore):
+
+   def test_load_utf8(self):
+        t = self.get_transport()
+        # From http://pad.lv/799212
+        unicode_user = u'Piotr O\u017carowski'
+        unicode_content = u'user=%s' % (unicode_user,)
+        utf8_content = unicode_content.encode('utf8')
+        # Store the raw content in the config file
+        t.put_bytes('foo.conf', utf8_content)
+        store = config.IniFileStore(t, 'foo.conf')
+        store.load()
+        stack = config.Stack([store.get_sections], store)
+        self.assertEquals(unicode_user, stack.get('user'))
+
+
 class TestMutableStore(TestStore):
 
     scenarios = [(key, {'store_id': key, 'get_store': builder}) for key, builder

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-06-18 13:57:17 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-06-20 09:31:17 +0000
@@ -29,6 +29,8 @@
 Bug Fixes
 *********
 
+* Properly load utf8-encoded config files. (Vincent Ladeuil, #799212)
+
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 



More information about the bazaar-commits mailing list