Mayil-AI-Sandbox / spring-framework_33422

Sandbox repository
Apache License 2.0
0 stars 1 forks source link

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

Open NobleMathews opened 1 month ago

NobleMathews commented 1 month ago

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.


public class TestMvConfiguration implements WebMvcConfigurer {

    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);
    }

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

}
mayil-ai[bot] commented 1 month ago

Here are some code snippets that may help you get started:

To address the issue with RedirectView failing to access path variable values when using PathPattern, follow these steps:

💡 To rerun Mayil, comment mayil-ai rerun. Mayil will incorporate any new context added to the ticket. Include details in your rerun comment to guide Mayil!