Skip to content

Commit 366ab55

Browse files
author
Jesse Kinkead
committed
Use the proper stack ordering when building a nested path in the Parser.
1 parent 07c67ae commit 366ab55

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

config/src/main/java/com/typesafe/config/impl/Parser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ private void parseInclude(Map<String, AbstractConfigValue> values) {
683683
}
684684

685685
if (!pathStack.isEmpty()) {
686-
Path prefix = new Path(pathStack);
686+
// The stack is in reverse order (most recent first on the
687+
// iterator), so build the path from the reversed iterator.
688+
Path prefix = new Path(pathStack.descendingIterator());
687689
obj = obj.relativized(prefix);
688690
}
689691

config/src/main/java/com/typesafe/config/impl/Path.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ final class Path {
3535

3636
// append all the paths in the list together into one path
3737
Path(List<Path> pathsToConcat) {
38-
if (pathsToConcat.isEmpty())
38+
this(pathsToConcat.iterator());
39+
}
40+
41+
// append all the paths in the iterator together into one path
42+
Path(Iterator<Path> i) {
43+
if (!i.hasNext())
3944
throw new ConfigException.BugOrBroken("empty path");
4045

41-
Iterator<Path> i = pathsToConcat.iterator();
4246
Path firstPath = i.next();
4347
this.first = firstPath.first;
4448

config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ class ConfigTest extends TestUtils {
10291029
assertEquals(3, resolved.getInt("foo.a.c"))
10301030
assertEquals(5, resolved.getInt("foo.b"))
10311031
assertEquals(10, resolved.getInt("foo.a.q"))
1032+
1033+
assertEquals(3, resolved.getInt("bar.nested.a.c"))
1034+
assertEquals(5, resolved.getInt("bar.nested.b"))
1035+
assertEquals(10, resolved.getInt("bar.nested.a.q"))
10321036
}
10331037

10341038
@Test

0 commit comments

Comments
 (0)