Skip to content

Commit

Permalink
Refine RequestMappingInfo path initialization
Browse files Browse the repository at this point in the history
Refining the change from 4370030 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
  • Loading branch information
rstoyanchev committed Dec 13, 2023
1 parent 409cecf commit 2acc7c6
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,21 @@ public RequestMappingInfo build() {
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();

Expand Down Expand Up @@ -784,9 +785,11 @@ public MutateBuilder(RequestMappingInfo other) {
@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) ?
Expand Down Expand Up @@ -873,6 +876,9 @@ public RequestMappingInfo build() {
*/
public static class BuilderConfiguration {

private static PathPatternParser defaultPatternParser = new PathPatternParser();


@Nullable
private PathPatternParser patternParser;

Expand Down Expand Up @@ -954,6 +960,20 @@ public PathMatcher getPathMatcher() {
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
Expand Down

0 comments on commit 2acc7c6

Please sign in to comment.