|
49 | 49 | * </p> |
50 | 50 | * |
51 | 51 | * @author Josh Cummings |
| 52 | + * @author Andrey Litvitski |
52 | 53 | * @since 6.5 |
53 | 54 | */ |
54 | 55 | public final class PathPatternRequestMatcher implements RequestMatcher { |
@@ -234,14 +235,15 @@ public static final class Builder { |
234 | 235 | * |
235 | 236 | * <p> |
236 | 237 | * Prefixes should be of the form {@code /my/prefix}, starting with a slash, not |
237 | | - * ending in a slash, and not containing and wildcards |
| 238 | + * ending in a slash, and not containing and wildcards The special value |
| 239 | + * {@code "/"} may be used to indicate the root context. |
238 | 240 | * @param basePath the path prefix |
239 | 241 | * @return the {@link Builder} for more configuration |
240 | 242 | */ |
241 | 243 | public Builder basePath(String basePath) { |
242 | 244 | Assert.notNull(basePath, "basePath cannot be null"); |
243 | 245 | Assert.isTrue(basePath.startsWith("/"), "basePath must start with '/'"); |
244 | | - Assert.isTrue(!basePath.endsWith("/"), "basePath must not end with a slash"); |
| 246 | + Assert.isTrue("/".equals(basePath) || !basePath.endsWith("/"), "basePath must not end with a slash"); |
245 | 247 | Assert.isTrue(!basePath.contains("*"), "basePath must not contain a star"); |
246 | 248 | return new Builder(this.parser, basePath); |
247 | 249 | } |
@@ -316,7 +318,8 @@ public PathPatternRequestMatcher matcher(String path) { |
316 | 318 | public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String path) { |
317 | 319 | Assert.notNull(path, "pattern cannot be null"); |
318 | 320 | Assert.isTrue(path.startsWith("/"), "pattern must start with a /"); |
319 | | - PathPattern pathPattern = this.parser.parse(this.basePath + path); |
| 321 | + String prefix = ("/".equals(this.basePath)) ? "" : this.basePath; |
| 322 | + PathPattern pathPattern = this.parser.parse(prefix + path); |
320 | 323 | return new PathPatternRequestMatcher(pathPattern, |
321 | 324 | (method != null) ? new HttpMethodRequestMatcher(method) : AnyRequestMatcher.INSTANCE); |
322 | 325 | } |
|
0 commit comments