Direct matches by URL path work again

This commit fixes a recent regression as a result of 5225a57411
with the determination of non-pattern vs pattern URLs. That in turn affects the ability to perform
direct matches by URL path.

There is also a fix in PathPattern to recognize "catch-all" patterns as pattern syntax.

See gh-24945
This commit is contained in:
Rossen Stoyanchev 2020-06-24 08:07:01 +01:00
parent 7e71749e34
commit 57f868fcbd
6 changed files with 17 additions and 5 deletions

View File

@ -190,7 +190,7 @@ public class PathPattern implements Comparable<PathPattern> {
* @since 5.2
*/
public boolean hasPatternSyntax() {
return (this.score > 0 || this.patternString.indexOf('?') != -1);
return (this.score > 0 || this.catchAll || this.patternString.indexOf('?') != -1);
}
/**

View File

@ -54,8 +54,8 @@ public class PathPatternTests {
public void hasPatternSyntax() {
PathPatternParser parser = new PathPatternParser();
assertThat(parser.parse("/foo/*").hasPatternSyntax()).isTrue();
assertThat(parser.parse("/foo/**").hasPatternSyntax()).isFalse();
assertThat(parser.parse("/foo/{*elem}").hasPatternSyntax()).isFalse();
assertThat(parser.parse("/foo/**").hasPatternSyntax()).isTrue();
assertThat(parser.parse("/foo/{*elem}").hasPatternSyntax()).isTrue();
assertThat(parser.parse("/f?o").hasPatternSyntax()).isTrue();
assertThat(parser.parse("/f*").hasPatternSyntax()).isTrue();
assertThat(parser.parse("/foo/{bar}/baz").hasPatternSyntax()).isTrue();

View File

@ -129,7 +129,7 @@ public final class PathPatternsRequestCondition extends AbstractRequestCondition
}
Set<String> result = Collections.emptySet();
for (PathPattern pattern : this.patterns) {
if (pattern.hasPatternSyntax()) {
if (!pattern.hasPatternSyntax()) {
result = (result.isEmpty() ? new HashSet<>(1) : result);
result.add(pattern.getPatternString());
}

View File

@ -218,7 +218,7 @@ public class PatternsRequestCondition extends AbstractRequestCondition<PatternsR
}
Set<String> result = Collections.emptySet();
for (String pattern : this.patterns) {
if (this.pathMatcher.isPattern(pattern)) {
if (!this.pathMatcher.isPattern(pattern)) {
result = (result.isEmpty() ? new HashSet<>(1) : result);
result.add(pattern);
}

View File

@ -48,6 +48,12 @@ public class PathPatternsRequestConditionTests {
.isEqualTo("");
}
@Test
void getDirectUrls() {
PathPatternsRequestCondition condition = createCondition("/something", "/else/**");
assertThat(condition.getDirectPaths()).containsExactly("/something");
}
@Test
void combineEmptySets() {
PathPatternsRequestCondition c1 = createCondition();

View File

@ -47,6 +47,12 @@ class PatternsRequestConditionTests {
.isEqualTo("");
}
@Test
void getDirectUrls() {
PatternsRequestCondition condition = new PatternsRequestCondition("/something", "/else/**");
assertThat(condition.getDirectPaths()).containsExactly("/something");
}
@Test
void combineEmptySets() {
PatternsRequestCondition c1 = new PatternsRequestCondition();