Browse Source

Fix incorrect weak ETag assertion

Closes gh-33376
6.0.x
Riley Park 1 year ago committed by rstoyanchev
parent
commit
f78b09fddf
  1. 7
      spring-web/src/main/java/org/springframework/http/HttpHeaders.java
  2. 8
      spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1044,9 +1044,8 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
*/ */
public void setETag(@Nullable String etag) { public void setETag(@Nullable String etag) {
if (etag != null) { if (etag != null) {
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/"), Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""), "ETag does not start with W/\" or \"");
"Invalid ETag: does not start with W/ or \""); Assert.isTrue(etag.endsWith("\""), "ETag does not end with \"");
Assert.isTrue(etag.endsWith("\""), "Invalid ETag: does not end with \"");
set(ETAG, etag); set(ETAG, etag);
} }
else { else {

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

@ -192,11 +192,17 @@ public class HttpHeadersTests {
} }
@Test @Test
void illegalETag() { void illegalETagWithoutQuotes() {
String eTag = "v2.6"; String eTag = "v2.6";
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag)); assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
} }
@Test
void illegalWeakETagWithoutLeadingQuote() {
String etag = "W/v2.6\"";
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(etag));
}
@Test @Test
void ifMatch() { void ifMatch() {
String ifMatch = "\"v2.6\""; String ifMatch = "\"v2.6\"";

Loading…
Cancel
Save