Browse Source

SPR-8059 fix issue with != param condition

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4408 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/merge
Rossen Stoyanchev 15 years ago
parent
commit
ac9a3d0541
  1. 8
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java
  2. 28
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java

8
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java

@ -75,8 +75,12 @@ abstract class ServletAnnotationMappingUtils { @@ -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;
}
}
}

28
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtilsTests.java

@ -77,6 +77,34 @@ public class ServletAnnotationMappingUtilsTests { @@ -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() {

Loading…
Cancel
Save