mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-25 13:32:30 +00:00
SEC-2888 AntPathRequestMatcher ignores variables in pattern when pattern
finishes with /**
This commit is contained in:
parent
e776a1fd35
commit
85955015f7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at
|
* the License. You may obtain a copy of the License at
|
||||||
@ -102,8 +102,9 @@ public final class AntPathRequestMatcher implements RequestMatcher {
|
|||||||
pattern = pattern.toLowerCase();
|
pattern = pattern.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the pattern ends with {@code /**} and has no other wildcards, then optimize to a sub-path match
|
// If the pattern ends with {@code /**} and has no other wildcards or path variables, then optimize to a sub-path match
|
||||||
if (pattern.endsWith(MATCH_ALL) && pattern.indexOf('?') == -1 &&
|
// TODO: use spring-framework AntPathMatcher.VARIABLE_PATTERN instead.
|
||||||
|
if (pattern.endsWith(MATCH_ALL) && (pattern.indexOf('?') == -1 && pattern.indexOf('{') == -1 && pattern.indexOf('}') == -1) &&
|
||||||
pattern.indexOf("*") == pattern.length() - 2) {
|
pattern.indexOf("*") == pattern.length() - 2) {
|
||||||
matcher = new SubpathMatcher(pattern.substring(0, pattern.length() - 3));
|
matcher = new SubpathMatcher(pattern.substring(0, pattern.length() - 3));
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,6 +71,26 @@ public class AntPathRequestMatcherTests {
|
|||||||
assertTrue(matcher.matches(createRequest("/blah/blah")));
|
assertTrue(matcher.matches(createRequest("/blah/blah")));
|
||||||
assertFalse(matcher.matches(createRequest("/blah/bleh")));
|
assertFalse(matcher.matches(createRequest("/blah/bleh")));
|
||||||
assertTrue(matcher.matches(createRequest("/blah/aaa/blah/bbb")));
|
assertTrue(matcher.matches(createRequest("/blah/aaa/blah/bbb")));
|
||||||
|
|
||||||
|
matcher = new AntPathRequestMatcher("/{id}/blAh/**");
|
||||||
|
assertTrue(matcher.matches(createRequest("/1234/blah")));
|
||||||
|
assertFalse(matcher.matches(createRequest("/4567/bleh")));
|
||||||
|
assertTrue(matcher.matches(createRequest("/paskos/blah/")));
|
||||||
|
assertTrue(matcher.matches(createRequest("/12345/blah/xxx")));
|
||||||
|
assertFalse(matcher.matches(createRequest("/12345/blaha")));
|
||||||
|
assertFalse(matcher.matches(createRequest("/paskos/bleh/")));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void trailingWildcardWithVariableMatchesCorrectly() {
|
||||||
|
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/{id}/blAh/**");
|
||||||
|
assertTrue(matcher.matches(createRequest("/1234/blah")));
|
||||||
|
assertFalse(matcher.matches(createRequest("/4567/bleh")));
|
||||||
|
assertTrue(matcher.matches(createRequest("/paskos/blah/")));
|
||||||
|
assertTrue(matcher.matches(createRequest("/12345/blah/xxx")));
|
||||||
|
assertFalse(matcher.matches(createRequest("/12345/blaha")));
|
||||||
|
assertFalse(matcher.matches(createRequest("/paskos/bleh/")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user