SPR-8059 fix issue with != param condition
This commit is contained in:
parent
7be1b5c3f5
commit
ce78a519f6
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue