Fix path within mapping when pattern contains ".*"

Prior to this commit, extracting the path within handler mapping would
result in "" if the matching path element would be a Regex and contain
".*". This could cause issues with resource handling if the handler
mapping pattern was similar to `"/folder/file.*.extension"`.

This commit introduces a new `isLiteral()` method in the `PathElement`
abstract class that expresses whether the path element can be compared
as a String for path matching or if it requires a more elaborate
matching process.

Using this method for extracting the path within handler mapping avoids
relying on wildcard count or other properties.

Fixes gh-29712
This commit is contained in:
Brian Clozel
2022-12-19 10:15:39 +01:00
parent b71db12c43
commit 5366ac84e6
5 changed files with 19 additions and 1 deletions

View File

@@ -686,6 +686,7 @@ public class PathPatternTests {
checkExtractPathWithinPattern("/docs/commit.html", "/docs/commit.html", "");
checkExtractPathWithinPattern("/docs/*", "/docs/cvs/commit", "cvs/commit");
checkExtractPathWithinPattern("/docs/cvs/*.html", "/docs/cvs/commit.html", "commit.html");
checkExtractPathWithinPattern("/docs/cvs/file.*.html", "/docs/cvs/file.sha.html", "file.sha.html");
checkExtractPathWithinPattern("/docs/**", "/docs/cvs/commit", "cvs/commit");
checkExtractPathWithinPattern("/doo/{*foobar}", "/doo/customer.html", "customer.html");
checkExtractPathWithinPattern("/doo/{*foobar}", "/doo/daa/customer.html", "daa/customer.html");