- Notifications
You must be signed in to change notification settings - Fork38.6k
Closed
Milestone
Description
Affects: 6.1.2+ (probably since the introduction of PathPatterns)
When you use aRedirectView
with an URI that contains a path variable, andPathPattern
s are enabled, then the variable value is missing.
This is due to the fact that thePathPattern
codepath ofAbstractUrlHandlerMapping
is callingbuildPathExposingHandler() with uriTemplateVariables parameter of null.
As a consequence noPathExposingHandlerInterceptor
is added to the execution chain. The variable values are never parsed from the URI.
WhenRedirectView
tries to access the variable values of the variables in the URI atreplaceUriTemplateVariables() it throws an IllegalArgumentException.
WhenAntPattern
s are used instead ofPathPattern
s, then the variable values are parsed and all is well.
@ConfigurationpublicclassTestMvConfigurationimplementsWebMvcConfigurer {@OverridepublicvoidaddViewControllers(ViewControllerRegistryregistry) {StringsrcPath ="/some/path/{variable}/foo";StringtgtPath ="/some/path/{variable}/bar";registry.addRedirectViewController(srcPath,tgtPath) .setStatusCode(HttpStatus.PERMANENT_REDIRECT); }@OverridepublicvoidconfigurePathMatch(PathMatchConfigurerconfigurer) {configurer.setPatternParser(newPathPatternParser());// broken// configurer.setPathMatcher(new AntPathMatcher()); // works }}