Fix root path test and add more test cases
This commit is contained in:
@@ -190,13 +190,13 @@ class DefaultPathSegmentContainer implements PathSegmentContainer {
|
||||
}
|
||||
|
||||
static PathSegmentContainer subPath(PathSegmentContainer container, int fromIndex, int toIndex) {
|
||||
if (fromIndex == toIndex) {
|
||||
return EMPTY_PATH;
|
||||
}
|
||||
List<PathSegment> segments = container.pathSegments();
|
||||
if (fromIndex == 0 && toIndex == segments.size()) {
|
||||
return container;
|
||||
}
|
||||
if (fromIndex == toIndex) {
|
||||
return EMPTY_PATH;
|
||||
}
|
||||
|
||||
Assert.isTrue(fromIndex < toIndex, "fromIndex: " + fromIndex + " should be < toIndex " + toIndex);
|
||||
Assert.isTrue(fromIndex >= 0 && fromIndex < segments.size(), "Invalid fromIndex: " + fromIndex);
|
||||
|
||||
@@ -130,6 +130,10 @@ public class DefaultPathSegmentContainerTests {
|
||||
assertEquals("/b/c", PathSegmentContainer.subPath(path, 1).value());
|
||||
assertEquals("/c", PathSegmentContainer.subPath(path, 2).value());
|
||||
|
||||
// root path
|
||||
path = PathSegmentContainer.parse("/", UTF_8);
|
||||
assertEquals("/", PathSegmentContainer.subPath(path, 0).value());
|
||||
|
||||
// trailing slash
|
||||
path = PathSegmentContainer.parse("/a/b/", UTF_8);
|
||||
assertEquals("/b/", PathSegmentContainer.subPath(path, 1).value());
|
||||
|
||||
@@ -39,6 +39,9 @@ public class DefaultRequestPathTests {
|
||||
// context path only
|
||||
testRequestPath("/a/b", "/a/b", "", false, true, false);
|
||||
|
||||
// root path
|
||||
testRequestPath("/", "", "/", false, true, false);
|
||||
|
||||
// empty path
|
||||
testRequestPath("", "", "", true, false, false);
|
||||
testRequestPath("", "/", "", true, false, false);
|
||||
|
||||
Reference in New Issue
Block a user