summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
+
+