Skip to content

Commit 2988a2c

Browse files
committed
Reconsider AntPathRequestMatcher matching logic
Closes gh-9285
1 parent 6499a23 commit 2988a2c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@
4848
* @author Luke Taylor
4949
* @author Rob Winch
5050
* @author Eddú Meléndez
51+
* @author Evgeniy Cheban
5152
* @since 3.1
5253
* @see org.springframework.util.AntPathMatcher
5354
*/
@@ -159,9 +160,12 @@ public Map<String, String> extractUriTemplateVariables(HttpServletRequest reques
159160

160161
@Override
161162
public MatchResult matcher(HttpServletRequest request) {
162-
if (this.matcher == null || !matches(request)) {
163+
if (!matches(request)) {
163164
return MatchResult.notMatch();
164165
}
166+
if (this.matcher == null) {
167+
return MatchResult.match();
168+
}
165169
String url = getRequestPath(request);
166170
return MatchResult.match(this.matcher.extractUriTemplateVariables(url));
167171
}

web/src/test/java/org/springframework/security/web/util/matcher/AntPathRequestMatcherTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
/**
3333
* @author Luke Taylor
3434
* @author Rob Winch
35+
* @author Evgeniy Cheban
3536
*/
3637
@RunWith(MockitoJUnitRunner.class)
3738
public class AntPathRequestMatcherTests {
@@ -196,6 +197,14 @@ public void matchesWithInvalidMethod() {
196197
assertThat(matcher.matches(request)).isFalse();
197198
}
198199

200+
// gh-9285
201+
@Test
202+
public void matcherWhenMatchAllPatternThenMatchResult() {
203+
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/**");
204+
MockHttpServletRequest request = createRequest("/blah");
205+
assertThat(matcher.matcher(request).isMatch()).isTrue();
206+
}
207+
199208
private HttpServletRequest createRequestWithNullMethod(String path) {
200209
given(this.request.getServletPath()).willReturn(path);
201210
return this.request;

0 commit comments

Comments
 (0)