This commit is contained in:
Rossen Stoyanchev 2017-06-30 16:11:55 -04:00
parent 8581afa621
commit 850083ca6c
2 changed files with 16 additions and 16 deletions

View File

@ -90,7 +90,7 @@ public class PathPattern implements Comparable<PathPattern> {
private boolean caseSensitive;
/** If this pattern has no trailing slash, allow candidates to include one and still match successfully */
boolean allowOptionalTrailingSlash;
private boolean allowOptionalTrailingSlash;
/** How many variables are captured in this pattern */
private int capturedVariableCount;
@ -122,8 +122,9 @@ public class PathPattern implements Comparable<PathPattern> {
private boolean catchAll = false;
PathPattern(String patternText, PathPatternParser parser, PathElement head, char separator, boolean caseSensitive,
boolean allowOptionalTrailingSlash) {
PathPattern(String patternText, PathPatternParser parser, @Nullable PathElement head,
char separator, boolean caseSensitive, boolean allowOptionalTrailingSlash) {
this.patternString = patternText;
this.parser = parser;
this.head = head;
@ -168,14 +169,11 @@ public class PathPattern implements Comparable<PathPattern> {
}
@Nullable
public PathRemainingMatchInfo getPathRemaining(@Nullable String path) {
return getPathRemaining(path != null ?
PathContainer.parse(path, StandardCharsets.UTF_8) : null);
public PathRemainingMatchInfo getPathRemaining(String path) {
return getPathRemaining(PathContainer.parse(path, StandardCharsets.UTF_8));
}
/**
* @param pathContainer the candidate path container to attempt to match against this pattern
* @return true if the path matches this pattern
@ -203,7 +201,7 @@ public class PathPattern implements Comparable<PathPattern> {
* or {@code null} if the path does not match this pattern
*/
@Nullable
public PathRemainingMatchInfo getPathRemaining(@Nullable PathContainer pathContainer) {
public PathRemainingMatchInfo getPathRemaining(PathContainer pathContainer) {
if (this.head == null) {
return new PathRemainingMatchInfo(pathContainer);
}
@ -487,7 +485,7 @@ public class PathPattern implements Comparable<PathPattern> {
private final Map<String, MultiValueMap<String, String>> matrixVariables;
public PathMatchResult(Map<String, String> uriVars,
PathMatchResult(Map<String, String> uriVars,
@Nullable Map<String, MultiValueMap<String, String>> matrixVars) {
this.uriVariables = Collections.unmodifiableMap(uriVars);
@ -522,11 +520,11 @@ public class PathPattern implements Comparable<PathPattern> {
private final PathMatchResult pathMatchResult;
PathRemainingMatchInfo(@Nullable PathContainer pathRemaining) {
PathRemainingMatchInfo(PathContainer pathRemaining) {
this(pathRemaining, PathMatchResult.EMPTY);
}
PathRemainingMatchInfo(@Nullable PathContainer pathRemaining, PathMatchResult pathMatchResult) {
PathRemainingMatchInfo(PathContainer pathRemaining, PathMatchResult pathMatchResult) {
this.pathRemaining = pathRemaining;
this.pathMatchResult = pathMatchResult;
}
@ -535,7 +533,7 @@ public class PathPattern implements Comparable<PathPattern> {
* Return the part of a path that was not matched by a pattern.
*/
public String getPathRemaining() {
return this.pathRemaining == null ? null: this.pathRemaining.value();
return this.pathRemaining.value();
}
/**
@ -727,7 +725,7 @@ public class PathPattern implements Comparable<PathPattern> {
* @param container a path container
* @return true if the container is not null and has more than zero elements
*/
private boolean hasLength(PathContainer container) {
private boolean hasLength(@Nullable PathContainer container) {
return container != null && container.elements().size() > 0;
}

View File

@ -39,6 +39,7 @@ import org.springframework.web.util.pattern.PathPattern.PathRemainingMatchInfo;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@ -339,24 +340,25 @@ public class PathPatternMatcherTests {
assertEquals("",parse("/resource/{*foo}").getPathRemaining(toPathContainer("/resource")).getPathRemaining());
PathPattern.PathRemainingMatchInfo pri = parse("/aaa/{bbb}/c?d/e*f/*/g").getPathRemaining(toPathContainer("/aaa/b/ccd/ef/x/g/i"));
assertNotNull(pri);
assertEquals("/i",pri.getPathRemaining());
assertEquals("b",pri.getUriVariables().get("bbb"));
pri = parse("/aaa/{bbb}/c?d/e*f/*/g/").getPathRemaining(toPathContainer("/aaa/b/ccd/ef/x/g/i"));
assertNotNull(pri);
assertEquals("i",pri.getPathRemaining());
assertEquals("b",pri.getUriVariables().get("bbb"));
pri = parse("/{aaa}_{bbb}/e*f/{x}/g").getPathRemaining(toPathContainer("/aa_bb/ef/x/g/i"));
assertNotNull(pri);
assertEquals("/i",pri.getPathRemaining());
assertEquals("aa",pri.getUriVariables().get("aaa"));
assertEquals("bb",pri.getUriVariables().get("bbb"));
assertEquals("x",pri.getUriVariables().get("x"));
assertNull(parse("/a/b").getPathRemaining(toPathContainer("")));
assertNull(parse("/a/b").getPathRemaining((String) null));
assertEquals("/a/b",parse("").getPathRemaining(toPathContainer("/a/b")).getPathRemaining());
assertEquals("",parse("").getPathRemaining(toPathContainer("")).getPathRemaining());
assertNull(parse("").getPathRemaining((String) null).getPathRemaining());
}
@Test