Refine RequestMappingInfo path initialization
Refining the change from 43700302c6
so that
we consistently pick a PathPatternParser (a) if it is provided, and (b)
if both PathPatternParser and PathMatcher are not provided. Also applying
the same in the mutate builder.
See gh-31662
This commit is contained in:
parent
409cecfff9
commit
2acc7c609f
|
@ -708,20 +708,21 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
|||
PathPatternsRequestCondition pathPatternsCondition = null;
|
||||
PatternsRequestCondition patternsCondition = null;
|
||||
|
||||
if (this.options.getPathMatcher() != null) {
|
||||
PathPatternParser parser = this.options.getPatternParserToUse();
|
||||
|
||||
if (parser != null) {
|
||||
pathPatternsCondition = (ObjectUtils.isEmpty(this.paths) ?
|
||||
EMPTY_PATH_PATTERNS :
|
||||
new PathPatternsRequestCondition(parser, this.paths));
|
||||
}
|
||||
else {
|
||||
patternsCondition = (ObjectUtils.isEmpty(this.paths) ?
|
||||
EMPTY_PATTERNS :
|
||||
new PatternsRequestCondition(
|
||||
this.paths, null, this.options.getPathMatcher(),
|
||||
this.paths, null, this.options.pathMatcher,
|
||||
this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
|
||||
this.options.getFileExtensions()));
|
||||
}
|
||||
else {
|
||||
PathPatternParser parser = (this.options.getPatternParser() != null ?
|
||||
this.options.getPatternParser() : new PathPatternParser());
|
||||
pathPatternsCondition = (ObjectUtils.isEmpty(this.paths) ?
|
||||
EMPTY_PATH_PATTERNS : new PathPatternsRequestCondition(parser, this.paths));
|
||||
}
|
||||
|
||||
ContentNegotiationManager manager = this.options.getContentNegotiationManager();
|
||||
|
||||
|
@ -784,9 +785,11 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
|||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Builder paths(String... paths) {
|
||||
if (this.options.patternParser != null) {
|
||||
PathPatternParser parser = this.options.getPatternParserToUse();
|
||||
|
||||
if (parser != null) {
|
||||
this.pathPatternsCondition = (ObjectUtils.isEmpty(paths) ?
|
||||
EMPTY_PATH_PATTERNS : new PathPatternsRequestCondition(this.options.patternParser, paths));
|
||||
EMPTY_PATH_PATTERNS : new PathPatternsRequestCondition(parser, paths));
|
||||
}
|
||||
else {
|
||||
this.patternsCondition = (ObjectUtils.isEmpty(paths) ?
|
||||
|
@ -873,6 +876,9 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
|||
*/
|
||||
public static class BuilderConfiguration {
|
||||
|
||||
private static PathPatternParser defaultPatternParser = new PathPatternParser();
|
||||
|
||||
|
||||
@Nullable
|
||||
private PathPatternParser patternParser;
|
||||
|
||||
|
@ -954,6 +960,20 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
|||
return this.pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@code PathPatternParser} to use, the one set explicitly
|
||||
* or falling back on a default instance if both {@code PathPatternParser}
|
||||
* and {@code PathMatcher} are not set.
|
||||
* @since 6.1.2
|
||||
*/
|
||||
@Nullable
|
||||
public PathPatternParser getPatternParserToUse() {
|
||||
if (this.patternParser == null && this.pathMatcher == null) {
|
||||
return defaultPatternParser;
|
||||
}
|
||||
return this.patternParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to apply trailing slash matching in PatternsRequestCondition.
|
||||
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
|
||||
|
|
Loading…
Reference in New Issue