summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2010-02-27 18:39:48 +0000
committerfuzzyman <devnull@localhost>2010-02-27 18:39:48 +0000
commit6e2b06158118d43382f201ef55bd1a9664283933 (patch)
treef80c8952ade56469ec749b2ed64fdf47d8b16d14
parenta1a9c089da21fa3cd511ebfef316aa70f44b1c08 (diff)
downloadconfigobj-6e2b06158118d43382f201ef55bd1a9664283933.tar.gz
Test and fix for interpolation matching a section name.
-rw-r--r--configobj.py4
-rw-r--r--functionaltests/test_configobj.py18
2 files changed, 20 insertions, 2 deletions
diff --git a/configobj.py b/configobj.py
index 7015c16..3827cee 100644
--- a/configobj.py
+++ b/configobj.py
@@ -380,11 +380,11 @@ class InterpolationEngine(object):
while True:
# try the current section first
val = current_section.get(key)
- if val is not None:
+ if val is not None and not isinstance(val, Section):
break
# try "DEFAULT" next
val = current_section.get('DEFAULT', {}).get(key)
- if val is not None:
+ if val is not None and not isinstance(val, Section):
break
# move up to parent and try again
# top-level's parent is itself
diff --git a/functionaltests/test_configobj.py b/functionaltests/test_configobj.py
index 53845e6..81e5441 100644
--- a/functionaltests/test_configobj.py
+++ b/functionaltests/test_configobj.py
@@ -61,5 +61,23 @@ class TestConfigObj(unittest.TestCase):
self.assertEqual(c.pop('a'), 3)
self.assertEqual(c.pop('b', 3), 3)
self.assertRaises(KeyError, c.pop, 'c')
+
+
+ def test_interpolation_with_section_names(self):
+ cfg = """
+item1 = 1234
+[section]
+ [[item1]]
+ foo='bar'
+ [[DEFAULT]]
+ [[[item1]]]
+ why = would you do this?
+ [[other-subsection]]
+ item2 = '$item1'""".splitlines()
+ c = ConfigObj(cfg, interpolation='Template')
+ # This raises an exception in 4.7.1 and earlier
+ repr(c)
+
+