Skip to content

Commit d2715d2

Browse files
kashikerstoyanchev
authored andcommitted
Fix incorrect weak ETag assertion
Closes gh-33377
1 parent 57b02da commit d2715d2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1037,9 +1037,8 @@ public long getDate() {
10371037
*/
10381038
public void setETag(@Nullable String etag) {
10391039
if (etag != null) {
1040-
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/"),
1041-
"Invalid ETag: does not start with W/ or \"");
1042-
Assert.isTrue(etag.endsWith("\""), "Invalid ETag: does not end with \"");
1040+
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""), "ETag does not start with W/\" or \"");
1041+
Assert.isTrue(etag.endsWith("\""), "ETag does not end with \"");
10431042
set(ETAG, etag);
10441043
}
10451044
else {

spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,17 @@ void ipv6Host() {
192192
}
193193

194194
@Test
195-
void illegalETag() {
195+
void illegalETagWithoutQuotes() {
196196
String eTag = "v2.6";
197197
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
198198
}
199199

200+
@Test
201+
void illegalWeakETagWithoutLeadingQuote() {
202+
String etag = "W/v2.6\"";
203+
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(etag));
204+
}
205+
200206
@Test
201207
void ifMatch() {
202208
String ifMatch = "\"v2.6\"";

0 commit comments

Comments
 (0)