Skip to content

Commit f78b09f

Browse files
kashikerstoyanchev
authored andcommitted
Fix incorrect weak ETag assertion
Closes gh-33376
1 parent b7ca746 commit f78b09f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Diff for: 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-2023 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.
@@ -1044,9 +1044,8 @@ public long getDate() {
10441044
*/
10451045
public void setETag(@Nullable String etag) {
10461046
if (etag != null) {
1047-
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/"),
1048-
"Invalid ETag: does not start with W/ or \"");
1049-
Assert.isTrue(etag.endsWith("\""), "Invalid ETag: does not end with \"");
1047+
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""), "ETag does not start with W/\" or \"");
1048+
Assert.isTrue(etag.endsWith("\""), "ETag does not end with \"");
10501049
set(ETAG, etag);
10511050
}
10521051
else {

Diff for: 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)