Add hasPatternSyntax method to PathPattern
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user