Add RequestPath tests for modifying the contextPath
This commit is contained in:
@@ -55,8 +55,7 @@ class DefaultRequestPath implements RequestPath {
|
||||
return PathContainer.parseUrlPath("");
|
||||
}
|
||||
|
||||
Assert.isTrue(contextPath.startsWith("/") && !contextPath.endsWith("/") &&
|
||||
path.value().startsWith(contextPath), "Invalid contextPath: " + contextPath);
|
||||
validateContextPath(path.value(), contextPath);
|
||||
|
||||
int length = contextPath.length();
|
||||
int counter = 0;
|
||||
@@ -70,8 +69,24 @@ class DefaultRequestPath implements RequestPath {
|
||||
}
|
||||
|
||||
// Should not happen..
|
||||
throw new IllegalStateException("Failed to initialize contextPath='" + contextPath + "'" +
|
||||
" given path='" + path.value() + "'");
|
||||
throw new IllegalStateException("Failed to initialize contextPath '" + contextPath + "'" +
|
||||
" for requestPath '" + path.value() + "'");
|
||||
}
|
||||
|
||||
private static void validateContextPath(String fullPath, String contextPath) {
|
||||
int length = contextPath.length();
|
||||
if (contextPath.charAt(0) != '/' || contextPath.charAt(length - 1) == '/') {
|
||||
throw new IllegalArgumentException("Invalid contextPath: '" + contextPath + "': " +
|
||||
"must start with '/' and not end with '/'");
|
||||
}
|
||||
if (!fullPath.startsWith(contextPath)) {
|
||||
throw new IllegalArgumentException("Invalid contextPath '" + contextPath + "': " +
|
||||
"must match the start of requestPath: '" + fullPath + "'");
|
||||
}
|
||||
if (fullPath.length() > length && fullPath.charAt(length) != '/') {
|
||||
throw new IllegalArgumentException("Invalid contextPath '" + contextPath + "': " +
|
||||
"must match to full path segments for requestPath: '" + fullPath + "'");
|
||||
}
|
||||
}
|
||||
|
||||
private static PathContainer extractPathWithinApplication(PathContainer fullPath, PathContainer contextPath) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public interface RequestPath extends PathContainer {
|
||||
|
||||
/**
|
||||
* Return a new {@code RequestPath} instance with a modified context path.
|
||||
* The new context path must match the beginning of this request path.
|
||||
* The new context path must match 0 or more path segments at the start.
|
||||
* @param contextPath the new context path
|
||||
* @return a new {@code RequestPath} instance
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user