diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java index 5bb507d42f25..8c4804dec52a 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java @@ -171,20 +171,17 @@ public MatchedResource getMatched(String path) if (_optimizedExact) { int i = path.length(); - - final Trie> exact_map = _exactMap; while (i >= 0) { - MappedResource candidate = exact_map.getBest(path, 0, i); + MappedResource 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; @@ -197,17 +194,15 @@ public MatchedResource getMatched(String path) if (_optimizedPrefix) { int i = path.length(); - final Trie> prefix_map = _prefixMap; while (i >= 0) { - MappedResource candidate = prefix_map.getBest(path, 0, i); + MappedResource 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,12 +215,16 @@ public MatchedResource getMatched(String path) if (_optimizedSuffix) { int i = 0; - final Trie> suffix_map = _suffixMap; + // 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 candidate = suffix_map.get(path, i + 1, path.length() - i - 1); + MappedResource candidate = _suffixMap.get(path, i + 1, path.length() - i - 1); if (candidate == null) - break; + continue; matchedPath = candidate.getPathSpec().matched(path); if (matchedPath != null) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/pathmap/PathMappingsTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/pathmap/PathMappingsTest.java index 8b0cae679eec..984f9623aba2 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/pathmap/PathMappingsTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/pathmap/PathMappingsTest.java @@ -324,6 +324,32 @@ public void testGetServletPathSpec() assertThat(p.get(new RegexPathSpec("/a/b/c")), nullValue()); } + @Test + public void testServletMultipleSuffixMappings() + { + PathMappings p = new PathMappings<>(); + p.put(new ServletPathSpec("*.foo"), "resourceFoo"); + p.put(new ServletPathSpec("*.bar"), "resourceBar"); + p.put(new ServletPathSpec("*.zed"), "resourceZed"); + + MatchedResource 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() {