mirror of
https://github.com/lightbend/config.git
synced 2025-01-26 12:10:08 +08:00
Merge pull request #137 from jkinkead/fix_nested_includes
Fix nested includes.
This commit is contained in:
commit
9c3907715c
@ -683,7 +683,9 @@ final class Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!pathStack.isEmpty()) {
|
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);
|
obj = obj.relativized(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,14 @@ final class Path {
|
|||||||
|
|
||||||
// append all the paths in the list together into one path
|
// append all the paths in the list together into one path
|
||||||
Path(List<Path> pathsToConcat) {
|
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");
|
throw new ConfigException.BugOrBroken("empty path");
|
||||||
|
|
||||||
Iterator<Path> i = pathsToConcat.iterator();
|
|
||||||
Path firstPath = i.next();
|
Path firstPath = i.next();
|
||||||
this.first = firstPath.first;
|
this.first = firstPath.first;
|
||||||
|
|
||||||
|
@ -3,3 +3,9 @@
|
|||||||
foo {
|
foo {
|
||||||
include "test09.conf"
|
include "test09.conf"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bar {
|
||||||
|
nested {
|
||||||
|
include "test09.conf"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1029,6 +1029,10 @@ class ConfigTest extends TestUtils {
|
|||||||
assertEquals(3, resolved.getInt("foo.a.c"))
|
assertEquals(3, resolved.getInt("foo.a.c"))
|
||||||
assertEquals(5, resolved.getInt("foo.b"))
|
assertEquals(5, resolved.getInt("foo.b"))
|
||||||
assertEquals(10, resolved.getInt("foo.a.q"))
|
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
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user