Description
David Kovac opened SPR-16879 and commented
Given the following RouterFunction
:
@Bean
public RouterFunction<ServerResponse> routerFunction() {
return nest(path("/test/{something}"),
route(GET("/info"), this::variables)
.andRoute(GET("/info/{foo}"), this::variables))
.andRoute(method(HttpMethod.GET), this::variables);
}
and handler:
private Mono<ServerResponse> variables(ServerRequest request) {
return ServerResponse.ok().body(fromObject(request.pathVariables()));
}
when client sends a request GET /test/spring/info
path variable (something) is never merged (not added to request attributes) as variables.isEmpty() in PathPatternPredicate#mergeTemplateVariables is in this case false. As a result no path variables will be returned in response.Expected: something=spring.
Path variable will be merged only in case there is another PathPatternPredicate with path variable, like GET("/info/{foo}"). Response for request GET /test/spring/info/bar will now contain something=spring and foo=bar.
Exposing of path variables was broken in 5.0.6 by #21233.
Expected behavior: path variables should be exposed if pattern matches
Affects: 5.0.6
Reference URL: https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-16879
Issue Links:
- PathVariable with nested router function throws IllegalArgumentException [SPR-16868] #21407 PathVariable with nested router function throws IllegalArgumentException ("duplicates")
- PathPatternPredicate leaves path variables in request even if predicate doesn't match [SPR-16692] #21233 PathPatternPredicate leaves path variables in request even if predicate doesn't match
Referenced from: pull request spring-attic/spring-framework-issues#180, and commits spring-attic/spring-framework-issues@b34056d, spring-attic/spring-framework-issues@472b271