Rev 6405: Robustly unquote configuration values (workaround configobj presenting a section as a dict in weird edge cases) in file:///home/vila/src/bzr/bugs/908050-protect-unquote/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Dec 23 09:24:36 UTC 2011


At file:///home/vila/src/bzr/bugs/908050-protect-unquote/

------------------------------------------------------------
revno: 6405
revision-id: v.ladeuil+lp at free.fr-20111223092436-duk4osp4j0jjvn9w
parent: pqm at pqm.ubuntu.com-20111222185258-wgcba8590pbw5sf1
fixes bug: https://launchpad.net/bugs/908050
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 908050-protect-unquote
timestamp: Fri 2011-12-23 10:24:36 +0100
message:
  Robustly unquote configuration values (workaround configobj presenting a section as a dict in weird edge cases)
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-12-21 21:31:03 +0000
+++ b/bzrlib/config.py	2011-12-23 09:24:36 +0000
@@ -3128,8 +3128,9 @@
             self._config_obj.list_values = False
 
     def unquote(self, value):
-        if value:
-            # _unquote doesn't handle None nor empty strings
+        if value and isinstance(value, basestring):
+            # _unquote doesn't handle None nor empty strings nor anything that
+            # is not a string, really.
             value = self._config_obj._unquote(value)
         return value
 

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-12-21 20:32:50 +0000
+++ b/bzrlib/tests/test_config.py	2011-12-23 09:24:36 +0000
@@ -2760,6 +2760,22 @@
             self.assertIdempotent('a,b')
 
 
+class TestDictFromStore(tests.TestCase):
+
+    def test_unquote_not_string(self):
+        conf = config.MemoryStack('x=2\n[a_section]\na=1\n')
+        value = conf.get('a_section')
+        # Urgh, despite 'conf' asking for the no-name section, we get the
+        # content of another section as a dict o_O
+        self.assertEquals({'a': '1'}, value)
+        unquoted = conf.store.unquote(value)
+        # Which cannot be unquoted but shouldn't crash either (the use cases
+        # are getting the value or displaying it. In the later case, '%s' will
+        # do).
+        self.assertEquals({'a': '1'}, unquoted)
+        self.assertEquals("{u'a': u'1'}", '%s' % (unquoted,))
+
+
 class TestIniFileStoreContent(tests.TestCaseWithTransport):
     """Simulate loading a config store with content of various encodings.
 

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-12-22 18:52:58 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-12-23 09:24:36 +0000
@@ -94,6 +94,10 @@
 * Report mistake trying to move a removed file with a non-ascii name without
   UnicodeEncodeError being raised. (Martin Packman, #898541)
 
+* Safely unquote configuration values in weird edge cases (a section seen as
+  a dictionary which is not a supported use case for the configuration
+  stacks). (Vincent Ladeuil, #908050)
+
 Documentation
 *************
 



More information about the bazaar-commits mailing list