File tree Expand file tree Collapse file tree
main/java/org/springframework/security/web/servlet/util/matcher
test/java/org/springframework/security/web/servlet/util/matcher Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -305,6 +305,19 @@ public boolean matches(HttpServletRequest request) {
305305 return this .method .name ().equals (request .getMethod ());
306306 }
307307
308+ @ Override
309+ public boolean equals (Object o ) {
310+ if (!(o instanceof HttpMethodRequestMatcher that )) {
311+ return false ;
312+ }
313+ return Objects .equals (this .method , that .method );
314+ }
315+
316+ @ Override
317+ public int hashCode () {
318+ return Objects .hash (this .method );
319+ }
320+
308321 @ Override
309322 public String toString () {
310323 return "HttpMethod [" + this .method + "]" ;
Original file line number Diff line number Diff line change @@ -145,6 +145,17 @@ void matcherWhenBasePathIsRootThenNoDoubleSlash() {
145145 assertThat (matcher .matches (mock )).isTrue ();
146146 }
147147
148+ // gh-18911
149+ @ Test
150+ void testEqualsWithSameAndDifferentHttpMethod () {
151+ PathPatternRequestMatcher .Builder builder = PathPatternRequestMatcher .withDefaults ();
152+ PathPatternRequestMatcher matcher1 = builder .matcher (HttpMethod .GET , "/foo" );
153+ PathPatternRequestMatcher matcher2 = builder .matcher (HttpMethod .GET , "/foo" );
154+ PathPatternRequestMatcher matcher3 = builder .matcher (HttpMethod .POST , "/foo" );
155+ assertThat (matcher1 ).isEqualTo (matcher2 );
156+ assertThat (matcher1 ).isNotEqualTo (matcher3 );
157+ }
158+
148159 MockHttpServletRequest request (String uri ) {
149160 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , uri );
150161 ServletRequestPathUtils .parseAndCache (request );
You can’t perform that action at this time.
0 commit comments