Browse Source

backported header matching fix for correct processing of negated header conditions (SPR-8862)

3.0.x
Juergen Hoeller 14 years ago
parent
commit
173f307ec9
  1. 27
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2011 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -75,8 +75,12 @@ abstract class ServletAnnotationMappingUtils {
boolean negated = separator > 0 && param.charAt(separator - 1) == '!'; boolean negated = separator > 0 && param.charAt(separator - 1) == '!';
String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1); String key = !negated ? param.substring(0, separator) : param.substring(0, separator - 1);
String value = param.substring(separator + 1); String value = param.substring(separator + 1);
if (!value.equals(request.getParameter(key))) { boolean match = value.equals(request.getParameter(key));
return negated; if (negated) {
match = !match;
}
if (!match) {
return false;
} }
} }
} }
@ -105,7 +109,7 @@ abstract class ServletAnnotationMappingUtils {
} }
} }
else { else {
boolean negated = separator > 0 && header.charAt(separator - 1) == '!'; boolean negated = (separator > 0 && header.charAt(separator - 1) == '!');
String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1); String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1);
String value = header.substring(separator + 1); String value = header.substring(separator + 1);
if (isMediaTypeHeader(key)) { if (isMediaTypeHeader(key)) {
@ -123,12 +127,21 @@ abstract class ServletAnnotationMappingUtils {
} }
} }
if (negated) {
found = !found;
}
if (!found) { if (!found) {
return negated; return false;
} }
} }
else if (!value.equals(request.getHeader(key))) { else {
return negated; boolean match = value.equals(request.getHeader(key));
if (negated) {
match = !match;
}
if (!match) {
return false;
}
} }
} }
} }

Loading…
Cancel
Save