Skip to content

Nested PathPatternPredicate doesn't expose path variables [SPR-16879] #21418

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: pull request spring-attic/spring-framework-issues#180, and commits spring-attic/spring-framework-issues@b34056d, spring-attic/spring-framework-issues@472b271

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions