Browse Source

Add hasPatternSyntax method to PathPattern

pull/22982/head
Rossen Stoyanchev 7 years ago
parent
commit
afc0ae3752
  1. 11
      spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java
  2. 10
      spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java

11
spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java

@ -175,6 +175,17 @@ public class PathPattern implements Comparable<PathPattern> { @@ -175,6 +175,17 @@ public class PathPattern implements Comparable<PathPattern> {
return this.patternString;
}
/**
* Whether the pattern string contains pattern syntax that would require
* use of {@link #matches(PathContainer)}, or if it is a regular String that
* could be compared directly to others.
* @since 5.2
*/
public boolean hasPatternSyntax() {
return this.score > 0 || this.patternString.indexOf('?') != -1;
}
/**
* Whether this pattern matches the given path.
* @param pathContainer the candidate path to attempt to match against

10
spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java

@ -57,6 +57,16 @@ public class PathPatternTests { @@ -57,6 +57,16 @@ public class PathPatternTests {
assertEquals("[/][/][/]",elementsToString(toPathContainer("///").elements()));
}
@Test
public void hasPatternSyntax() {
PathPatternParser parser = new PathPatternParser();
assertTrue(parser.parse("/foo/*").hasPatternSyntax());
assertTrue(parser.parse("/foo/**/bar").hasPatternSyntax());
assertTrue(parser.parse("/f?o").hasPatternSyntax());
assertTrue(parser.parse("/foo/{bar}/baz").hasPatternSyntax());
assertFalse(parser.parse("/foo/bar").hasPatternSyntax());
}
@Test
public void matching_LiteralPathElement() {
checkMatches("foo", "foo");

Loading…
Cancel
Save