Merge pull request #137 from jkinkead/fix_nested_includes

Fix nested includes.
This commit is contained in:
Havoc Pennington 2014-01-30 10:10:08 -08:00
commit 9c3907715c
4 changed files with 19 additions and 3 deletions

View File

@ -683,7 +683,9 @@ final class Parser {
}
if (!pathStack.isEmpty()) {
Path prefix = new Path(pathStack);
// The stack is in reverse order (most recent first on the
// iterator), so build the path from the reversed iterator.
Path prefix = new Path(pathStack.descendingIterator());
obj = obj.relativized(prefix);
}

View File

@ -35,10 +35,14 @@ final class Path {
// append all the paths in the list together into one path
Path(List<Path> pathsToConcat) {
if (pathsToConcat.isEmpty())
this(pathsToConcat.iterator());
}
// append all the paths in the iterator together into one path
Path(Iterator<Path> i) {
if (!i.hasNext())
throw new ConfigException.BugOrBroken("empty path");
Iterator<Path> i = pathsToConcat.iterator();
Path firstPath = i.next();
this.first = firstPath.first;

View File

@ -3,3 +3,9 @@
foo {
include "test09.conf"
}
bar {
nested {
include "test09.conf"
}
}

View File

@ -1029,6 +1029,10 @@ class ConfigTest extends TestUtils {
assertEquals(3, resolved.getInt("foo.a.c"))
assertEquals(5, resolved.getInt("foo.b"))
assertEquals(10, resolved.getInt("foo.a.q"))
assertEquals(3, resolved.getInt("bar.nested.a.c"))
assertEquals(5, resolved.getInt("bar.nested.b"))
assertEquals(10, resolved.getInt("bar.nested.a.q"))
}
@Test