Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
c2bc103cb9
commit
5fddbf9bb1
|
@ -176,16 +176,15 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||
int i = path.length();
|
||||
while (i >= 0)
|
||||
{
|
||||
MappedResource<E> candidate = _exactMap.getBest(path, 0, i);
|
||||
MappedResource<E> candidate = _exactMap.getBest(path, 0, i--);
|
||||
if (candidate == null)
|
||||
break;
|
||||
continue;
|
||||
|
||||
matchedPath = candidate.getPathSpec().matched(path);
|
||||
if (matchedPath != null)
|
||||
{
|
||||
return new MatchedResource<>(candidate.getResource(), candidate.getPathSpec(), matchedPath);
|
||||
}
|
||||
i--;
|
||||
}
|
||||
// If we reached here, there's NO optimized EXACT Match possible, skip simple match below
|
||||
skipRestOfGroup = true;
|
||||
|
@ -200,14 +199,13 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||
int i = path.length();
|
||||
while (i >= 0)
|
||||
{
|
||||
MappedResource<E> candidate = _prefixMap.getBest(path, 0, i);
|
||||
MappedResource<E> candidate = _prefixMap.getBest(path, 0, i--);
|
||||
if (candidate == null)
|
||||
break;
|
||||
continue;
|
||||
|
||||
matchedPath = candidate.getPathSpec().matched(path);
|
||||
if (matchedPath != null)
|
||||
return new MatchedResource<>(candidate.getResource(), candidate.getPathSpec(), matchedPath);
|
||||
i--;
|
||||
}
|
||||
// If we reached here, there's NO optimized PREFIX Match possible, skip simple match below
|
||||
skipRestOfGroup = true;
|
||||
|
@ -220,11 +218,16 @@ public class PathMappings<E> implements Iterable<MappedResource<E>>, Dumpable
|
|||
if (_optimizedSuffix)
|
||||
{
|
||||
int i = 0;
|
||||
// Loop through each suffix mark
|
||||
// Input is "/a.b.c.foo"
|
||||
// Loop 1: "b.c.foo"
|
||||
// Loop 2: "c.foo"
|
||||
// Loop 3: "foo"
|
||||
while ((i = path.indexOf('.', i + 1)) > 0)
|
||||
{
|
||||
MappedResource<E> candidate = _suffixMap.get(path, i + 1, path.length() - i - 1);
|
||||
if (candidate == null)
|
||||
break;
|
||||
continue;
|
||||
|
||||
matchedPath = candidate.getPathSpec().matched(path);
|
||||
if (matchedPath != null)
|
||||
|
|
|
@ -319,6 +319,32 @@ public class PathMappingsTest
|
|||
assertThat(p.get(new RegexPathSpec("/a/b/c")), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServletMultipleSuffixMappings()
|
||||
{
|
||||
PathMappings<String> p = new PathMappings<>();
|
||||
p.put(new ServletPathSpec("*.foo"), "resourceFoo");
|
||||
p.put(new ServletPathSpec("*.bar"), "resourceBar");
|
||||
p.put(new ServletPathSpec("*.zed"), "resourceZed");
|
||||
|
||||
MatchedResource<String> matched;
|
||||
|
||||
matched = p.getMatched("/a.b.c.foo");
|
||||
assertThat(matched.getResource(), is("resourceFoo"));
|
||||
|
||||
matched = p.getMatched("/a.b.c.bar");
|
||||
assertThat(matched.getResource(), is("resourceBar"));
|
||||
|
||||
matched = p.getMatched("/a.b.c.pop");
|
||||
assertNull(matched);
|
||||
|
||||
matched = p.getMatched("/a.foo.c.pop");
|
||||
assertNull(matched);
|
||||
|
||||
matched = p.getMatched("/a%2Efoo");
|
||||
assertNull(matched);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveUriTemplatePathSpec()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue