Ensure correct recognition for start of match-the-rest path elements
Without this change the /{*foobar} and /** path elements were
not correctly enforcing that the first character they encounter
must be a separator. This problem was introduced when adjusting
the generated path element chains for these constructs. Originally
the generated chain included a SeparatorPathElement but in order for
these to match 'nothing' (i.e. /foo matches /foo/{*foobar}) the separator
path element was removed, so the separator enforcement needed moving
into the CaptureTheRestPathElement and WildcardTheRestPathElement.
Issue: SPR-14544
This commit is contained in:
committed by
Brian Clozel
parent
f58ffad939
commit
f786feb5e1
@@ -45,6 +45,12 @@ class CaptureTheRestPathElement extends PathElement {
|
||||
// No need to handle 'match start' checking as this captures everything
|
||||
// anyway and cannot be followed by anything else
|
||||
// assert next == null
|
||||
|
||||
// If there is more data, it must start with the separator
|
||||
if (candidateIndex<matchingContext.candidateLength &&
|
||||
matchingContext.candidate[candidateIndex] != separator) {
|
||||
return false;
|
||||
}
|
||||
while ((candidateIndex+1)<matchingContext.candidateLength &&
|
||||
matchingContext.candidate[candidateIndex+1] == separator) {
|
||||
candidateIndex++;
|
||||
|
||||
@@ -34,6 +34,11 @@ class WildcardTheRestPathElement extends PathElement {
|
||||
|
||||
@Override
|
||||
public boolean matches(int candidateIndex, MatchingContext matchingContext) {
|
||||
// If there is more data, it must start with the separator
|
||||
if (candidateIndex < matchingContext.candidateLength &&
|
||||
matchingContext.candidate[candidateIndex] != separator) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,11 @@ public class PathPatternMatcherTests {
|
||||
|
||||
@Test
|
||||
public void captureTheRest() {
|
||||
checkMatches("/resource/{*foobar}", "/resource");
|
||||
checkNoMatch("/resource/{*foobar}", "/resourceX");
|
||||
checkNoMatch("/resource/{*foobar}", "/resourceX/foobar");
|
||||
checkMatches("/resource/{*foobar}", "/resource/foobar");
|
||||
checkCapture("/resource/{*foobar}", "/resource/foobar", "foobar", "/foobar");
|
||||
checkCapture("/customer/{*something}", "/customer/99", "something", "/99");
|
||||
checkCapture("/customer/{*something}", "/customer/aa/bb/cc", "something",
|
||||
"/aa/bb/cc");
|
||||
@@ -124,6 +129,11 @@ public class PathPatternMatcherTests {
|
||||
checkMatches("a/*","a/");
|
||||
checkMatches("a/*","a/a");
|
||||
checkNoMatch("a/*","a/a/");
|
||||
|
||||
checkMatches("/resource/**", "/resource");
|
||||
checkNoMatch("/resource/**", "/resourceX");
|
||||
checkNoMatch("/resource/**", "/resourceX/foobar");
|
||||
checkMatches("/resource/**", "/resource/foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user