@@ -55,8 +55,7 @@ private static PathContainer initContextPath(PathContainer path, @Nullable Strin
55
55
return PathContainer .parseUrlPath ("" );
56
56
}
57
57
58
- Assert .isTrue (contextPath .startsWith ("/" ) && !contextPath .endsWith ("/" ) &&
59
- path .value ().startsWith (contextPath ), "Invalid contextPath: " + contextPath );
58
+ validateContextPath (path .value (), contextPath );
60
59
61
60
int length = contextPath .length ();
62
61
int counter = 0 ;
@@ -70,8 +69,24 @@ private static PathContainer initContextPath(PathContainer path, @Nullable Strin
70
69
}
71
70
72
71
// Should not happen..
73
- throw new IllegalStateException ("Failed to initialize contextPath='" + contextPath + "'" +
74
- " given path='" + path .value () + "'" );
72
+ throw new IllegalStateException ("Failed to initialize contextPath '" + contextPath + "'" +
73
+ " for requestPath '" + path .value () + "'" );
74
+ }
75
+
76
+ private static void validateContextPath (String fullPath , String contextPath ) {
77
+ int length = contextPath .length ();
78
+ if (contextPath .charAt (0 ) != '/' || contextPath .charAt (length - 1 ) == '/' ) {
79
+ throw new IllegalArgumentException ("Invalid contextPath: '" + contextPath + "': " +
80
+ "must start with '/' and not end with '/'" );
81
+ }
82
+ if (!fullPath .startsWith (contextPath )) {
83
+ throw new IllegalArgumentException ("Invalid contextPath '" + contextPath + "': " +
84
+ "must match the start of requestPath: '" + fullPath + "'" );
85
+ }
86
+ if (fullPath .length () > length && fullPath .charAt (length ) != '/' ) {
87
+ throw new IllegalArgumentException ("Invalid contextPath '" + contextPath + "': " +
88
+ "must match to full path segments for requestPath: '" + fullPath + "'" );
89
+ }
75
90
}
76
91
77
92
private static PathContainer extractPathWithinApplication (PathContainer fullPath , PathContainer contextPath ) {
0 commit comments