Rev 5126: (vila) Ensure config options containing triple quotes won't corrupt config in file:///home/pqm/archives/thelove/bzr/2.2/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Feb 22 10:55:00 UTC 2011
At file:///home/pqm/archives/thelove/bzr/2.2/
------------------------------------------------------------
revno: 5126 [merge]
revision-id: pqm at pqm.ubuntu.com-20110222105457-jpab4zf6t21liwj3
parent: pqm at pqm.ubuntu.com-20110209055700-dspebroykbj4sfl5
parent: bialix at ukr.net-20110222091828-qhrwi4epm6f09dtu
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.2
timestamp: Tue 2011-02-22 10:54:57 +0000
message:
(vila) Ensure config options containing triple quotes won't corrupt config
files. (Alexander Belchenko)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
bzrlib/util/configobj/configobj.py configobj.py-20051018184548-06992a2246425e3e
=== modified file 'NEWS'
--- a/NEWS 2011-02-09 04:16:55 +0000
+++ b/NEWS 2011-02-20 13:41:43 +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
*******
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-07-21 03:07:02 +0000
+++ b/bzrlib/tests/test_config.py 2011-02-22 09:18:28 +0000
@@ -241,11 +241,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
More information about the bazaar-commits
mailing list