Skip to content
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

AntPathMatcher fails to match paths ending with '/' when pattern contains '**' #30506

Closed
mguelton opened this issue May 19, 2023 · 1 comment
Closed
Labels
status: invalid An issue that we don't feel is valid

Comments

@mguelton
Copy link

Affects: 6.0.9

The tests below are successful:

assertThat(pathMatcher.match("bla/test/*", "bla/test/")).isTrue();
assertThat(pathMatcher.match("**/test/", "bla/test/")).isTrue();

then the following test should be successful too but fails:

assertThat(pathMatcher.match("**/test/*", "bla/test/")).isTrue();

The issue is located in https://github.com/spring-projects/spring-framework/blob/e5ee369e70e0a8ca04437f502649b11171a1c741/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java#LL278C1-L281C1

A possible fix:

if (pattIdxEnd == (pattDirs.length - 1)) {
	if (pattDirs[pattIdxEnd].equals("*") && path.endsWith(pathSeparator)) {
		pattIdxEnd--;
		continue;
	}
	if (pattern.endsWith(this.pathSeparator) != path.endsWith(this.pathSeparator)) {
		return false;
	}
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 19, 2023
@rstoyanchev
Copy link
Contributor

This is by design. A a single * matches only the current segment. The trailing slash is the root of the next segment.

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2023
@rstoyanchev rstoyanchev added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants