Use the proper stack ordering when building a nested path in the Parser.

This commit is contained in:
Jesse Kinkead 2014-01-29 13:30:37 -08:00
parent 07c67aed2e
commit 366ab55582
3 changed files with 13 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

@ -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