Rev 6413: (vila) Robustly unquote configuration values (Vincent Ladeuil) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jan 3 12:04:04 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6413 [merge]
revision-id: pqm at pqm.ubuntu.com-20120103120403-05m286q87wkbygl6
parent: pqm at pqm.ubuntu.com-20120103113801-y3t2hw4fdjzj3wuy
parent: v.ladeuil+lp at free.fr-20111223092436-duk4osp4j0jjvn9w
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2012-01-03 12:04:03 +0000
message:
  (vila) Robustly unquote configuration values (Vincent Ladeuil)
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2012-01-03 10:24:01 +0000
+++ b/bzrlib/config.py	2012-01-03 12:04:03 +0000
@@ -3138,8 +3138,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	2012-01-03 09:45:52 +0000
+++ b/bzrlib/tests/test_config.py	2012-01-03 12:04:03 +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	2012-01-03 10:24:01 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-01-03 12:04:03 +0000
@@ -98,6 +98,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