diff --git a/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java b/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java index 226cbd34464..81a3539b368 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -21,34 +21,20 @@ import java.util.LinkedHashMap; import java.util.Map; /** - * PathMatcher implementation for Ant-style path patterns. - * Examples are provided below. + * PathMatcher implementation for Ant-style path patterns. Examples are provided below. * - *
Part of this mapping code has been kindly borrowed from - * Apache Ant. + *
Part of this mapping code has been kindly borrowed from Apache Ant. * - *
The mapping matches URLs using the following rules:
- *
The mapping matches URLs using the following rules:
Some examples:
- *
com/t?st.jsp - matches com/test.jsp but also
- * com/tast.jsp or com/txst.jspcom/*.jsp - matches all .jsp files in the
- * com directorycom/**/test.jsp - matches all test.jsp
- * files underneath the com pathorg/springframework/**/*.jsp - matches all .jsp
- * files underneath the org/springframework pathorg/**/servlet/bla.jsp - matches
- * org/springframework/servlet/bla.jsp but also
- * org/springframework/testing/servlet/bla.jsp and
- * org/servlet/bla.jspSome examples:
com/t?st.jsp - matches com/test.jsp but also
+ * com/tast.jsp or com/txst.jspcom/*.jsp - matches all
+ * .jsp files in the com directorycom/**/test.jsp - matches all
+ * test.jsp files underneath the com pathorg/springframework/**/*.jsp
+ * - matches all .jsp files underneath the org/springframework pathorg/**/servlet/bla.jsp - matches org/springframework/servlet/bla.jsp but also
+ * org/springframework/testing/servlet/bla.jsp and org/servlet/bla.jsppath against the given pattern.
+ *
* @param pattern the pattern to match against
* @param path the path String to test
- * @param fullMatch whether a full pattern match is required
- * (else a pattern match as far as the given base path goes is sufficient)
- * @return true if the supplied path matched,
- * false if it didn't
+ * @param fullMatch whether a full pattern match is required (else a pattern match as far as the given base path goes
+ * is sufficient)
+ * @return true if the supplied path matched, false if it didn't
*/
- protected boolean doMatch(String pattern, String path, boolean fullMatch, Mapnull.
- * @param str string which must be matched against the pattern.
- * Must not be null.
- * @return true if the string matches against the
- * pattern, or false otherwise.
+ * Tests whether or not a string matches against a pattern. The pattern may contain two special characters:null.
+ * @param str string which must be matched against the pattern. Must not be null.
+ * @return true if the string matches against the pattern, or false otherwise.
*/
private boolean matchStrings(String pattern, String str, MapFor example: - *
For example:
/docs/cvs/commit.html' and '/docs/cvs/commit.html -> ''/docs/*' and '/docs/cvs/commit -> 'cvs/commit'/docs/cvs/*.html' and '/docs/cvs/commit.html -> 'commit.html'/docs/**\/*.html' and '/docs/cvs/commit.html -> 'cvs/commit.html'/*.html' and '/docs/cvs/commit.html -> 'docs/cvs/commit.html'*.html' and '/docs/cvs/commit.html -> '/docs/cvs/commit.html'*' and '/docs/cvs/commit.html -> '/docs/cvs/commit.html'Assumes that {@link #match} returns true for 'pattern'
- * and 'path', but does not enforce this.
+ *
*' and '/docs/cvs/commit.html -> '/docs/cvs/commit.html'Assumes that {@link #match} returns true for 'pattern' and 'path', but
+ * does not enforce this.
*/
public String extractPathWithinPattern(String pattern, String path) {
String[] patternParts = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator);
@@ -291,26 +267,17 @@ public class AntPathMatcher implements PathMatcher {
}
/**
- * Combines two patterns into a new pattern that is returned.
- *
This implementation simply concatenates the two patterns, unless the - * first pattern contains a file extension match (such as {@code *.html}. In - * that case, the second pattern should be included in the first, or an - * {@code IllegalArgumentException} is thrown. - *
For example: - *
| Pattern 1 | Pattern 2 | Result |
|---|---|---|
| /hotels | {@code null} | /hotels |
| {@code null} | /hotels | /hotels |
| /hotels | /bookings | /hotels/bookings |
| /hotels | bookings | /hotels/bookings |
| /hotels/* | /bookings | /hotels/bookings |
| /hotels/** | /bookings | /hotels/**/bookings |
| /hotels | {hotel} | /hotels/{hotel} |
| /hotels/* | {hotel} | /hotels/{hotel} |
| Pattern 1 | Pattern 2 | Result |
|---|---|---|
| /hotels | {@code + * null} | /hotels |
| {@code null} | /hotels | /hotels |
| /hotels | /bookings | /hotels/bookings |
| /hotels | bookings | /hotels/bookings |
| /hotels/* | /bookings | /hotels/bookings |
| /hotels/** | /bookings | /hotels/**/bookings |
| /hotels | {hotel} | /hotels/{hotel} |
| /hotels/* | {hotel} | /hotels/{hotel} |
| /hotels/** | {hotel} | /hotels/**/{hotel} |
| /*.html | /hotels.html | /hotels.html |
| /*.html | /hotels | IllegalArgumentException |