Skip to content

Commit 1703b71

Browse files
kashikerstoyanchev
authored andcommitted
Fix incorrect weak ETag assertion
See gh-33374
1 parent 1911ca7 commit 1703b71

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ public long getDate() {
10481048
*/
10491049
public void setETag(@Nullable String etag) {
10501050
if (etag != null) {
1051-
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/"),
1052-
"Invalid ETag: does not start with W/ or \"");
1051+
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""),
1052+
"Invalid ETag: does not start with W/\" or \"");
10531053
Assert.isTrue(etag.endsWith("\""), "Invalid ETag: does not end with \"");
10541054
set(ETAG, etag);
10551055
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ void illegalETag() {
196196
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
197197
}
198198

199+
@Test
200+
void illegalETagWithoutQuoteAfterWSlash() {
201+
String etag = "W/v2.6\"";
202+
assertThatIllegalArgumentException().as("Invalid Weak ETag").isThrownBy(() -> headers.setETag(etag));
203+
}
204+
199205
@Test
200206
void ifMatch() {
201207
String ifMatch = "\"v2.6\"";

0 commit comments

Comments
 (0)