Method level only, empty RequestMapping matches "" and "/"
Closes gh-30293
This commit is contained in:
@@ -255,6 +255,16 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
pprc.getPatternValues() : ((PatternsRequestCondition) condition).getPatterns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the request mapping has an empty URL path mapping.
|
||||
* @since 6.0.10
|
||||
*/
|
||||
public boolean isEmptyMapping() {
|
||||
RequestCondition<?> condition = getActivePatternsCondition();
|
||||
return (condition instanceof PathPatternsRequestCondition pprc ?
|
||||
pprc.isEmptyPathMapping() : ((PatternsRequestCondition) condition).isEmptyPathMapping());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP request methods of this {@link RequestMappingInfo};
|
||||
* or instance with 0 request methods (never {@code null}).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -305,6 +305,9 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
if (typeInfo != null) {
|
||||
info = typeInfo.combine(info);
|
||||
}
|
||||
if (info.isEmptyMapping()) {
|
||||
info = info.mutate().paths("", "/").options(this.config).build();
|
||||
}
|
||||
String prefix = getPathPrefix(handlerType);
|
||||
if (prefix != null) {
|
||||
info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);
|
||||
|
||||
@@ -192,7 +192,16 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl
|
||||
request.setServletPath("");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
|
||||
assertThat(response.getContentAsString()).isEqualTo("test");
|
||||
|
||||
// gh-30293
|
||||
request = new MockHttpServletRequest("GET", "/");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
|
||||
assertThat(response.getContentAsString()).isEqualTo("test");
|
||||
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest
|
||||
|
||||
Reference in New Issue
Block a user