diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java index 14d854a31fa..a6c7e41fe8e 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java @@ -75,8 +75,12 @@ abstract class ServletAnnotationMappingUtils { boolean negated = separator > 0 && param.charAt(separator - 1) == '!'; String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1); String value = param.substring(separator + 1); - if (!value.equals(request.getParameter(key))) { - return negated; + boolean match = value.equals(request.getParameter(key)); + if (negated) { + match = !match; + } + if (!match) { + return false; } } } diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java index f11dc01bfb2..ca645ec89b2 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java @@ -77,6 +77,34 @@ public class ServletAnnotationMappingUtilsTests { boolean result = ServletAnnotationMappingUtils.checkParameters(params, request); assertFalse("Invalid request method result", result); } + + @Test + public void checkParametersNegatedValueMatch() { + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); + request.addParameter("param1", "value1"); + String[] params = new String[]{"param1!=foo"}; + boolean result = ServletAnnotationMappingUtils.checkParameters(params, request); + assertTrue("Invalid request method result", result); + } + + @Test + public void checkParametersNegatedValueNoMatch() { + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); + request.addParameter("param1", "foo"); + String[] params = new String[]{"param1!=foo"}; + boolean result = ServletAnnotationMappingUtils.checkParameters(params, request); + assertFalse("Invalid request method result", result); + } + + @Test + public void checkParametersCompositeNoMatch() { + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); + request.addParameter("param1", "foo"); + request.addParameter("param2", "foo"); + String[] params = new String[]{"param1=foo", "param2!=foo"}; + boolean result = ServletAnnotationMappingUtils.checkParameters(params, request); + assertFalse("[SPR-8059] Invalid request method result", result); + } @Test public void checkHeadersSimpleMatch() {