Fix PathPattern incorrectly matching variable against root path
Issue: SPR-15264
This commit is contained in:
@@ -80,7 +80,8 @@ class CaptureVariablePathElement extends PathElement {
|
|||||||
}
|
}
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
match = (nextPos == matchingContext.candidateLength);
|
// Needs to be at least one character #SPR15264
|
||||||
|
match = (nextPos == matchingContext.candidateLength && nextPos > candidateIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (matchingContext.isMatchStartMatching && nextPos == matchingContext.candidateLength) {
|
if (matchingContext.isMatchStartMatching && nextPos == matchingContext.candidateLength) {
|
||||||
|
|||||||
@@ -507,6 +507,31 @@ public class PathPatternMatcherTests {
|
|||||||
checkExtractPathWithinPattern("/", "//", "");
|
checkExtractPathWithinPattern("/", "//", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void extractUriTemplateVariables_spr15264() {
|
||||||
|
PathPattern pp = new PathPatternParser().parse("/{foo}");
|
||||||
|
assertTrue(pp.matches("/abc"));
|
||||||
|
assertFalse(pp.matches("/"));
|
||||||
|
assertFalse(pp.matches("//"));
|
||||||
|
checkCapture("/{foo}", "/abc", "foo", "abc");
|
||||||
|
|
||||||
|
pp = new PathPatternParser().parse("/{foo}/{bar}");
|
||||||
|
assertTrue(pp.matches("/abc/def"));
|
||||||
|
assertFalse(pp.matches("//def"));
|
||||||
|
assertFalse(pp.matches("//"));
|
||||||
|
|
||||||
|
pp = parse("/{foo}/boo");
|
||||||
|
assertTrue(pp.matches("/abc/boo"));
|
||||||
|
assertTrue(pp.matches("/a/boo"));
|
||||||
|
assertFalse(pp.matches("//boo"));
|
||||||
|
|
||||||
|
checkCapture("/{word:[a-z]*}", "/abc", "word", "abc");
|
||||||
|
pp = parse("/{word:[a-z]*}");
|
||||||
|
assertFalse(pp.matches("/1"));
|
||||||
|
assertTrue(pp.matches("/a"));
|
||||||
|
assertFalse(pp.matches("/"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extractUriTemplateVariables() throws Exception {
|
public void extractUriTemplateVariables() throws Exception {
|
||||||
checkCapture("/hotels/{hotel}", "/hotels/1", "hotel", "1");
|
checkCapture("/hotels/{hotel}", "/hotels/1", "hotel", "1");
|
||||||
|
|||||||
Reference in New Issue
Block a user