Merge lp:~bialix/bzr/2.3-configobj into lp:bzr/2.3

Proposed by Alexander Belchenko
Status: Merged
Approved by: Martin Pool
Approved revision: no longer in the source branch.
Merged at revision: 5623
Proposed branch: lp:~bialix/bzr/2.3-configobj
Merge into: lp:bzr/2.3
Diff against target: 75 lines (+35/-3)
3 files modified
bzrlib/tests/test_config.py (+27/-1)
bzrlib/util/configobj/configobj.py (+4/-2)
doc/en/release-notes/bzr-2.2.txt (+4/-0)
To merge this branch: bzr merge lp:~bialix/bzr/2.3-configobj
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+50511@code.launchpad.net

Description of the change

This branch has the same fix as lp:~bialix/bzr/2.2-configobj, see MP: https://code.launchpad.net/~bialix/bzr/2.2-configobj/+merge/50507 but now it's prepared for inclusion into 2.3 series. I've fixed merge conflict of NEWS entry, there is no other changes.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/test_config.py'
2--- bzrlib/tests/test_config.py 2011-01-10 22:20:12 +0000
3+++ bzrlib/tests/test_config.py 2011-02-22 09:51:57 +0000
4@@ -309,11 +309,37 @@
5 """
6 co = config.ConfigObj()
7 co['test'] = 'foo#bar'
8- lines = co.write()
9+ outfile = StringIO()
10+ co.write(outfile=outfile)
11+ lines = outfile.getvalue().splitlines()
12 self.assertEqual(lines, ['test = "foo#bar"'])
13 co2 = config.ConfigObj(lines)
14 self.assertEqual(co2['test'], 'foo#bar')
15
16+ def test_triple_quotes(self):
17+ # Bug #710410: if the value string has triple quotes
18+ # then ConfigObj versions up to 4.7.2 will quote them wrong
19+ # and won't able to read them back
20+ triple_quotes_value = '''spam
21+""" that's my spam """
22+eggs'''
23+ co = config.ConfigObj()
24+ co['test'] = triple_quotes_value
25+ # While writing this test another bug in ConfigObj has been found:
26+ # method co.write() without arguments produces list of lines
27+ # one option per line, and multiline values are not split
28+ # across multiple lines,
29+ # and that breaks the parsing these lines back by ConfigObj.
30+ # This issue only affects test, but it's better to avoid
31+ # `co.write()` construct at all.
32+ # [bialix 20110222] bug report sent to ConfigObj's author
33+ outfile = StringIO()
34+ co.write(outfile=outfile)
35+ output = outfile.getvalue()
36+ # now we're trying to read it back
37+ co2 = config.ConfigObj(StringIO(output))
38+ self.assertEquals(triple_quotes_value, co2['test'])
39+
40
41 erroneous_config = """[section] # line 1
42 good=good # line 2
43
44=== modified file 'bzrlib/util/configobj/configobj.py'
45--- bzrlib/util/configobj/configobj.py 2009-04-17 22:24:54 +0000
46+++ bzrlib/util/configobj/configobj.py 2011-02-22 09:51:57 +0000
47@@ -1794,10 +1794,12 @@
48 def _get_triple_quote(self, value):
49 if (value.find('"""') != -1) and (value.find("'''") != -1):
50 raise ConfigObjError('Value "%s" cannot be safely quoted.' % value)
51+ # upstream version (up to version 4.7.2) has the bug with incorrect quoting;
52+ # fixed in our copy based on the suggestion of ConfigObj's author
53 if value.find('"""') == -1:
54+ quot = tsquot
55+ else:
56 quot = tdquot
57- else:
58- quot = tsquot
59 return quot
60
61
62
63=== modified file 'doc/en/release-notes/bzr-2.2.txt'
64--- doc/en/release-notes/bzr-2.2.txt 2011-02-09 08:24:25 +0000
65+++ doc/en/release-notes/bzr-2.2.txt 2011-02-22 09:51:57 +0000
66@@ -36,6 +36,10 @@
67 Internals
68 *********
69
70+* Fixed bug in the bundled copy of ConfigObj with quoting of triple quotes
71+ in the value string. Fix suggested by ConfigObj's author Michael Foord.
72+ (Alexander Belchenko, #710410)
73+
74 Testing
75 *******
76

Subscribers

People subscribed via source and target branches