Fix incorrect weak ETag assertion

See gh-33374
This commit is contained in:
Riley Park
2024-08-12 19:45:30 -07:00
committed by rstoyanchev
parent 1911ca728d
commit 1703b71563
2 changed files with 8 additions and 2 deletions

View File

@@ -1048,8 +1048,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
*/
public void setETag(@Nullable String etag) {
if (etag != null) {
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/"),
"Invalid ETag: does not start with W/ or \"");
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""),
"Invalid ETag: does not start with W/\" or \"");
Assert.isTrue(etag.endsWith("\""), "Invalid ETag: does not end with \"");
set(ETAG, etag);
}

View File

@@ -196,6 +196,12 @@ class HttpHeadersTests {
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
}
@Test
void illegalETagWithoutQuoteAfterWSlash() {
String etag = "W/v2.6\"";
assertThatIllegalArgumentException().as("Invalid Weak ETag").isThrownBy(() -> headers.setETag(etag));
}
@Test
void ifMatch() {
String ifMatch = "\"v2.6\"";