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;
|
PathPatternsRequestCondition pathPatternsCondition = null;
|
||||||
PatternsRequestCondition patternsCondition = 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) ?
|
patternsCondition = (ObjectUtils.isEmpty(this.paths) ?
|
||||||
EMPTY_PATTERNS :
|
EMPTY_PATTERNS :
|
||||||
new PatternsRequestCondition(
|
new PatternsRequestCondition(
|
||||||
this.paths, null, this.options.getPathMatcher(),
|
this.paths, null, this.options.pathMatcher,
|
||||||
this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
|
this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
|
||||||
this.options.getFileExtensions()));
|
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();
|
ContentNegotiationManager manager = this.options.getContentNegotiationManager();
|
||||||
|
|
||||||
|
@ -784,9 +785,11 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public Builder paths(String... paths) {
|
public Builder paths(String... paths) {
|
||||||
if (this.options.patternParser != null) {
|
PathPatternParser parser = this.options.getPatternParserToUse();
|
||||||
|
|
||||||
|
if (parser != null) {
|
||||||
this.pathPatternsCondition = (ObjectUtils.isEmpty(paths) ?
|
this.pathPatternsCondition = (ObjectUtils.isEmpty(paths) ?
|
||||||
EMPTY_PATH_PATTERNS : new PathPatternsRequestCondition(this.options.patternParser, paths));
|
EMPTY_PATH_PATTERNS : new PathPatternsRequestCondition(parser, paths));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.patternsCondition = (ObjectUtils.isEmpty(paths) ?
|
this.patternsCondition = (ObjectUtils.isEmpty(paths) ?
|
||||||
|
@ -873,6 +876,9 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
*/
|
*/
|
||||||
public static class BuilderConfiguration {
|
public static class BuilderConfiguration {
|
||||||
|
|
||||||
|
private static PathPatternParser defaultPatternParser = new PathPatternParser();
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private PathPatternParser patternParser;
|
private PathPatternParser patternParser;
|
||||||
|
|
||||||
|
@ -954,6 +960,20 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||||
return this.pathMatcher;
|
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.
|
* Set whether to apply trailing slash matching in PatternsRequestCondition.
|
||||||
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
|
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
|
||||||
|
|
Loading…
Reference in New Issue