Skip to content

Commit 4a21fb2

Browse files
committed
Fix root path test and add more test cases
1 parent 67e482a commit 4a21fb2

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/DefaultPathSegmentContainer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ private static void parseParamValues(String input, Charset charset, MultiValueMa
190190
}
191191

192192
static PathSegmentContainer subPath(PathSegmentContainer container, int fromIndex, int toIndex) {
193-
if (fromIndex == toIndex) {
194-
return EMPTY_PATH;
195-
}
196193
List<PathSegment> segments = container.pathSegments();
197194
if (fromIndex == 0 && toIndex == segments.size()) {
198195
return container;
199196
}
197+
if (fromIndex == toIndex) {
198+
return EMPTY_PATH;
199+
}
200200

201201
Assert.isTrue(fromIndex < toIndex, "fromIndex: " + fromIndex + " should be < toIndex " + toIndex);
202202
Assert.isTrue(fromIndex >= 0 && fromIndex < segments.size(), "Invalid fromIndex: " + fromIndex);

spring-web/src/test/java/org/springframework/http/server/reactive/DefaultPathSegmentContainerTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public void subPath() throws Exception {
130130
assertEquals("/b/c", PathSegmentContainer.subPath(path, 1).value());
131131
assertEquals("/c", PathSegmentContainer.subPath(path, 2).value());
132132

133+
// root path
134+
path = PathSegmentContainer.parse("/", UTF_8);
135+
assertEquals("/", PathSegmentContainer.subPath(path, 0).value());
136+
133137
// trailing slash
134138
path = PathSegmentContainer.parse("/a/b/", UTF_8);
135139
assertEquals("/b/", PathSegmentContainer.subPath(path, 1).value());

spring-web/src/test/java/org/springframework/http/server/reactive/DefaultRequestPathTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public void requestPath() throws Exception {
3939
// context path only
4040
testRequestPath("/a/b", "/a/b", "", false, true, false);
4141

42+
// root path
43+
testRequestPath("/", "", "/", false, true, false);
44+
4245
// empty path
4346
testRequestPath("", "", "", true, false, false);
4447
testRequestPath("", "/", "", true, false, false);

0 commit comments

Comments
 (0)