Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Joakim Erdfelt 2022-06-21 15:25:02 -05:00
commit 6da27fcaaa
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
2 changed files with 36 additions and 7 deletions

View File

@ -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)

View File

@ -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()
{