|
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 { |
@@ -200,14 +201,15 @@ public static final class Builder { |
200 | 201 | * |
201 | 202 | * <p> |
202 | 203 | * Prefixes should be of the form {@code /my/prefix}, starting with a slash, not |
203 | | - * ending in a slash, and not containing and wildcards |
| 204 | + * ending in a slash, and not containing and wildcards The special value |
| 205 | + * {@code "/"} may be used to indicate the root context. |
204 | 206 | * @param basePath the path prefix |
205 | 207 | * @return the {@link Builder} for more configuration |
206 | 208 | */ |
207 | 209 | public Builder basePath(String basePath) { |
208 | 210 | Assert.notNull(basePath, "basePath cannot be null"); |
209 | 211 | Assert.isTrue(basePath.startsWith("/"), "basePath must start with '/'"); |
210 | | - Assert.isTrue(!basePath.endsWith("/"), "basePath must not end with a slash"); |
| 212 | + Assert.isTrue("/".equals(basePath) || !basePath.endsWith("/"), "basePath must not end with a slash"); |
211 | 213 | Assert.isTrue(!basePath.contains("*"), "basePath must not contain a star"); |
212 | 214 | return new Builder(this.parser, basePath); |
213 | 215 | } |
@@ -282,7 +284,8 @@ public PathPatternRequestMatcher matcher(String path) { |
282 | 284 | public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String path) { |
283 | 285 | Assert.notNull(path, "pattern cannot be null"); |
284 | 286 | Assert.isTrue(path.startsWith("/"), "pattern must start with a /"); |
285 | | - PathPattern pathPattern = this.parser.parse(this.basePath + path); |
| 287 | + String prefix = ("/".equals(this.basePath)) ? "" : this.basePath; |
| 288 | + PathPattern pathPattern = this.parser.parse(prefix + path); |
286 | 289 | return new PathPatternRequestMatcher(pathPattern, |
287 | 290 | (method != null) ? new HttpMethodRequestMatcher(method) : AnyRequestMatcher.INSTANCE); |
288 | 291 | } |
|
0 commit comments