Fix hashcode/equals issue in HeadersRequestCondition
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,6 +64,8 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
return this.isNegated;
|
||||
}
|
||||
|
||||
protected abstract boolean isCaseSensitiveName();
|
||||
|
||||
protected abstract T parseValue(String valueExpression);
|
||||
|
||||
public final boolean match(HttpServletRequest request) {
|
||||
@@ -88,7 +90,9 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
}
|
||||
if (obj != null && obj instanceof AbstractNameValueExpression) {
|
||||
AbstractNameValueExpression<?> other = (AbstractNameValueExpression<?>) obj;
|
||||
return ((this.name.equalsIgnoreCase(other.name)) &&
|
||||
String thisName = isCaseSensitiveName() ? this.name : this.name.toLowerCase();
|
||||
String otherName = isCaseSensitiveName() ? other.name : other.name.toLowerCase();
|
||||
return ((thisName.equalsIgnoreCase(otherName)) &&
|
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) &&
|
||||
this.isNegated == other.isNegated);
|
||||
}
|
||||
@@ -97,7 +101,7 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
int result = isCaseSensitiveName() ? name.hashCode() : name.toLowerCase().hashCode();
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
result = 31 * result + (isNegated ? 1 : 0);
|
||||
return result;
|
||||
|
||||
@@ -139,6 +139,11 @@ public final class HeadersRequestCondition extends AbstractRequestCondition<Head
|
||||
super(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCaseSensitiveName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parseValue(String valueExpression) {
|
||||
return valueExpression;
|
||||
@@ -153,14 +158,6 @@ public final class HeadersRequestCondition extends AbstractRequestCondition<Head
|
||||
protected boolean matchValue(HttpServletRequest request) {
|
||||
return value.equals(request.getHeader(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.toLowerCase().hashCode();
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
result = 31 * result + (isNegated ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,6 +131,11 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
|
||||
super(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCaseSensitiveName() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parseValue(String valueExpression) {
|
||||
return valueExpression;
|
||||
|
||||
Reference in New Issue
Block a user