Relax multiple segment matching constraints in PathPattern

Prior to this commit, gh-35213 allowed wildcard path elments at the
start of path patterns. This came with an additional constraint that
rejected such patterns if the pattern segment following the wildcard one
was not a literal:

* `/**/{name}` was rejected
* `/**/something/{name}` was accepted

The motivation here was to make the performance impact of wildard
patterns as small as possible at runtime.

This commit relaxes this constraint because `/**/*.js` patterns are very
popular in the security space for request matchers.

Closes gh-35686
This commit is contained in:
Brian Clozel
2025-11-05 18:32:44 +01:00
parent 8bb63081a8
commit 285182be27
5 changed files with 10 additions and 27 deletions
@@ -232,7 +232,6 @@ class PathPatternParserTests {
checkError("/{abc}{*foobar}", 1, PatternMessage.CAPTURE_ALL_IS_STANDALONE_CONSTRUCT);
checkError("/{abc}{*foobar}{foo}", 1, PatternMessage.CAPTURE_ALL_IS_STANDALONE_CONSTRUCT);
checkError("/{*foo}/foo/{*bar}", 18, PatternMessage.CANNOT_HAVE_MANY_MULTISEGMENT_PATHELEMENTS);
checkError("/{*foo}/{bar}", 8, PatternMessage.MULTISEGMENT_PATHELEMENT_NOT_FOLLOWED_BY_LITERAL);
checkError("{foo:}", 5, PatternMessage.MISSING_REGEX_CONSTRAINT);
checkError("{foo}_{foo}", 0, PatternMessage.ILLEGAL_DOUBLE_CAPTURE, "foo");
checkError("/{bar}/{bar}", 7, PatternMessage.ILLEGAL_DOUBLE_CAPTURE, "bar");
@@ -185,6 +185,16 @@ class PathPatternTests {
checkMatches("/resource/**", "/resource/foobar");
}
@Test
void wildcardSegmentsThenNonLiteral() {
checkMatches("/**/*.js", "/script.js");
checkMatches("/**/*.js", "/js/script.js");
checkMatches("/**/*.js", "/files/js/script.js");
checkMatches("/**/{type}/*.js", "/files/js/script.js");
checkNoMatch("/**/*.js", "/files/style.css");
}
@Test
void antPathMatcherTests() {
// test exact matching