Rev 5623: Merge fix for bug #710410 from 2.2 in http://bazaar.launchpad.net/~vila/bzr/2.3-integration/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Feb 22 11:24:36 UTC 2011


At http://bazaar.launchpad.net/~vila/bzr/2.3-integration/

------------------------------------------------------------
revno: 5623 [merge]
revision-id: v.ladeuil+lp at free.fr-20110222112436-5ci4vz63rv32olgm
parent: pqm at pqm.ubuntu.com-20110209093024-hx6rkxscaotvf0qy
parent: bialix at ukr.net-20110222094945-nrq437j6bhjgrdh8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 2.3.1-dev
timestamp: Tue 2011-02-22 12:24:36 +0100
message:
  Merge fix for bug #710410 from 2.2
modified:
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  bzrlib/util/configobj/configobj.py configobj.py-20051018184548-06992a2246425e3e
  doc/en/release-notes/bzr-2.2.txt bzr2.2.txt-20101008081016-21wd86gpfhllpue3-39
-------------- next part --------------
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-01-10 22:20:12 +0000
+++ b/bzrlib/tests/test_config.py	2011-02-22 09:49:45 +0000
@@ -309,11 +309,37 @@
         """
         co = config.ConfigObj()
         co['test'] = 'foo#bar'
-        lines = co.write()
+        outfile = StringIO()
+        co.write(outfile=outfile)
+        lines = outfile.getvalue().splitlines()
         self.assertEqual(lines, ['test = "foo#bar"'])
         co2 = config.ConfigObj(lines)
         self.assertEqual(co2['test'], 'foo#bar')
 
+    def test_triple_quotes(self):
+        # Bug #710410: if the value string has triple quotes
+        # then ConfigObj versions up to 4.7.2 will quote them wrong
+        # and won't able to read them back
+        triple_quotes_value = '''spam
+""" that's my spam """
+eggs'''
+        co = config.ConfigObj()
+        co['test'] = triple_quotes_value
+        # While writing this test another bug in ConfigObj has been found:
+        # method co.write() without arguments produces list of lines
+        # one option per line, and multiline values are not split
+        # across multiple lines,
+        # and that breaks the parsing these lines back by ConfigObj.
+        # This issue only affects test, but it's better to avoid
+        # `co.write()` construct at all.
+        # [bialix 20110222] bug report sent to ConfigObj's author
+        outfile = StringIO()
+        co.write(outfile=outfile)
+        output = outfile.getvalue()
+        # now we're trying to read it back
+        co2 = config.ConfigObj(StringIO(output))
+        self.assertEquals(triple_quotes_value, co2['test'])
+
 
 erroneous_config = """[section] # line 1
 good=good # line 2

=== modified file 'bzrlib/util/configobj/configobj.py'
--- a/bzrlib/util/configobj/configobj.py	2009-04-17 22:24:54 +0000
+++ b/bzrlib/util/configobj/configobj.py	2011-02-22 09:17:40 +0000
@@ -1794,10 +1794,12 @@
     def _get_triple_quote(self, value):
         if (value.find('"""') != -1) and (value.find("'''") != -1):
             raise ConfigObjError('Value "%s" cannot be safely quoted.' % value)
+        # upstream version (up to version 4.7.2) has the bug with incorrect quoting;
+        # fixed in our copy based on the suggestion of ConfigObj's author
         if value.find('"""') == -1:
+            quot = tsquot
+        else:
             quot = tdquot
-        else:
-            quot = tsquot
         return quot
 
 

=== modified file 'doc/en/release-notes/bzr-2.2.txt'
--- a/doc/en/release-notes/bzr-2.2.txt	2011-02-09 08:24:25 +0000
+++ b/doc/en/release-notes/bzr-2.2.txt	2011-02-20 15:01:25 +0000
@@ -36,6 +36,10 @@
 Internals
 *********
 
+* Fixed bug in the bundled copy of ConfigObj with quoting of triple quotes
+  in the value string. Fix suggested by ConfigObj's author Michael Foord.
+  (Alexander Belchenko, #710410)
+
 Testing
 *******
 



More information about the bazaar-commits mailing list