Skip to content

Support "*" catch-all mappings for MockMvc Filter registrations #28041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
*/
final class PatternMappingFilterProxy implements Filter {

private static final String EXTENSION_MAPPING_PATTERN = "*.";
private static final String ALL_MAPPING_PATTERN = "*";

private static final String PATH_MAPPING_PATTERN = "/*";
private static final String EXTENSION_MAPPING_PATTERN = ALL_MAPPING_PATTERN + ".";

private static final String PATH_MAPPING_PATTERN = "/" + ALL_MAPPING_PATTERN;

private final Filter delegate;

Expand Down Expand Up @@ -73,7 +75,7 @@ private void addUrlPattern(String urlPattern) {
if (urlPattern.startsWith(EXTENSION_MAPPING_PATTERN)) {
this.endsWithMatches.add(urlPattern.substring(1));
}
else if (urlPattern.equals(PATH_MAPPING_PATTERN)) {
else if (urlPattern.equals(PATH_MAPPING_PATTERN) || urlPattern.equals(ALL_MAPPING_PATTERN)) {
this.startsWithMatches.add("");
}
else if (urlPattern.endsWith(PATH_MAPPING_PATTERN)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void matchPathMappingAllFolder() throws Exception {

@Test
public void matchPathMappingAll() throws Exception {
assertFilterInvoked("/test", "/*");
assertFilterInvoked("/test", "*");
}

@Test
Expand Down