Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path variable values missing in RedirectView when PathPattern are used #33422

Closed
buletti opened this issue Aug 23, 2024 · 0 comments
Closed

Path variable values missing in RedirectView when PathPattern are used #33422

buletti opened this issue Aug 23, 2024 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@buletti
Copy link

buletti commented Aug 23, 2024

Affects: 6.1.2+ (probably since the introduction of PathPatterns)


When you use a RedirectView with an URI that contains a path variable, and PathPatterns are enabled, then the variable value is missing.

This is due to the fact that the PathPattern codepath of AbstractUrlHandlerMapping is calling buildPathExposingHandler() with uriTemplateVariables parameter of null.

As a consequence no PathExposingHandlerInterceptor is added to the execution chain. The variable values are never parsed from the URI.

When RedirectView tries to access the variable values of the variables in the URI at replaceUriTemplateVariables() it throws an IllegalArgumentException.

When AntPatterns are used instead of PathPatterns, then the variable values are parsed and all is well.

@Configuration
public class TestMvConfiguration implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        String srcPath = "/some/path/{variable}/foo"; 
        String tgtPath = "/some/path/{variable}/bar";
        registry.addRedirectViewController(srcPath, tgtPath)
                .setStatusCode(HttpStatus.PERMANENT_REDIRECT);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setPatternParser(new PathPatternParser());  // broken
//       configurer.setPathMatcher(new AntPathMatcher());      // works
    }

}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 23, 2024
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Aug 23, 2024
@bclozel bclozel self-assigned this Sep 10, 2024
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 11, 2024
@bclozel bclozel added this to the 6.1.14 milestone Sep 11, 2024
bclozel added a commit to bclozel/spring-framework that referenced this issue Sep 11, 2024
Prior to this commit, the URL handler mapping would expose the matching
pattern, the path within mapping and matching URI variables as request
attributes. This was the case when the mapping would use the
`AntPathMatcher` as matching infrastructure, but not when using the
`PathPattern` variant. In this case, the map of URI variables would be
`null`. This could throw `IllegalArgumentException` when `RedirectView`
instances were relying on the presence of specific variables.

This commit ensures that URI variables are also extracted when the
`PathPatternParser` is used.

Fixes spring-projectsgh-33422
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants