Skip to content

Commit

Permalink
Fix edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaucher committed Dec 11, 2024
1 parent e504e8a commit b837469
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions java/org/apache/catalina/servlets/DefaultServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,9 @@ protected boolean checkIfMatch(HttpServletRequest request, HttpServletResponse r
return true;
}
boolean hasAsteriskValue = false;// check existence of special header value '*'
int headerCount = 0;
while (headerValues.hasMoreElements() && !conditionSatisfied) {
headerCount++;
String headerValue = headerValues.nextElement();
if ("*".equals(headerValue)) {
hasAsteriskValue = true;
Expand All @@ -2237,7 +2239,11 @@ protected boolean checkIfMatch(HttpServletRequest request, HttpServletResponse r
}
}
}
if (hasAsteriskValue && headerValues.hasMoreElements()) {
if (headerValues.hasMoreElements()) {
headerCount++;
}

if (hasAsteriskValue && headerCount > 1) {
// Note that an If-Match header field with a list value containing "*" and other values (including other
// instances of "*") is syntactically invalid (therefore not allowed to be generated) and furthermore is
// unlikely to be interoperable.
Expand Down Expand Up @@ -2312,13 +2318,14 @@ protected boolean checkIfNoneMatch(HttpServletRequest request, HttpServletRespon
}
boolean hasAsteriskValue = false;// check existence of special header value '*'
boolean conditionSatisfied = true;
int headerCount = 0;
while (headerValues.hasMoreElements()) {

headerCount++;
String headerValue = headerValues.nextElement();

if (headerValue.equals("*")) {
hasAsteriskValue = true;
if (headerValues.hasMoreElements()) {
if (headerCount > 1 || headerValues.hasMoreElements()) {
conditionSatisfied = false;
break;
} else {
Expand Down Expand Up @@ -2358,8 +2365,11 @@ protected boolean checkIfNoneMatch(HttpServletRequest request, HttpServletRespon
}

}
if (headerValues.hasMoreElements()) {
headerCount++;
}

if (hasAsteriskValue && headerValues.hasMoreElements()) {
if (hasAsteriskValue && headerCount > 1) {
// Note that an If-None-Match header field with a list value containing "*" and other values (including
// other instances of "*") is syntactically invalid (therefore not allowed to be generated) and furthermore
// is unlikely to be interoperable.
Expand Down

0 comments on commit b837469

Please sign in to comment.