Skip to content

Commit 99302fd

Browse files
committed
AntPathMatcher#isPattern also checks URI vars
Closes gh-22959
1 parent 5aa0de7 commit 99302fd

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -169,7 +169,21 @@ private void deactivatePatternCache() {
169169

170170
@Override
171171
public boolean isPattern(String path) {
172-
return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
172+
boolean uriVar = false;
173+
for (int i = 0; i < path.length(); i++) {
174+
char c = path.charAt(i);
175+
if (c == '*' || c == '?') {
176+
return true;
177+
}
178+
if (c == '{') {
179+
uriVar = true;
180+
continue;
181+
}
182+
if (c == '}' && uriVar) {
183+
return true;
184+
}
185+
}
186+
return false;
173187
}
174188

175189
@Override

spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java

Lines changed: 11 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-2019 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.
@@ -681,4 +681,14 @@ public void extensionMappingWithDotPathSeparator() {
681681
"/*.html.hotel.*", pathMatcher.combine("/*.html", "hotel.*"));
682682
}
683683

684+
@Test // gh-22959
685+
public void isPattern() {
686+
assertTrue(pathMatcher.isPattern("/test/*"));
687+
assertTrue(pathMatcher.isPattern("/test/**/name"));
688+
assertTrue(pathMatcher.isPattern("/test?"));
689+
assertTrue(pathMatcher.isPattern("/test/{name}"));
690+
assertFalse(pathMatcher.isPattern("/test/name"));
691+
assertFalse(pathMatcher.isPattern("/test/foo{bar"));
692+
}
693+
684694
}

0 commit comments

Comments
 (0)