Skip to content

Commit

Permalink
Fix incorrect weak ETag assertion
Browse files Browse the repository at this point in the history
Closes gh-33376
  • Loading branch information
kashike authored and rstoyanchev committed Aug 13, 2024
1 parent b7ca746 commit f78b09f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1044,9 +1044,8 @@ public long getDate() {
*/
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.endsWith("\""), "Invalid ETag: does not end with \"");
Assert.isTrue(etag.startsWith("\"") || etag.startsWith("W/\""), "ETag does not start with W/\" or \"");
Assert.isTrue(etag.endsWith("\""), "ETag does not end with \"");
set(ETAG, etag);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,17 @@ void ipv6Host() {
}

@Test
void illegalETag() {
void illegalETagWithoutQuotes() {
String eTag = "v2.6";
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
}

@Test
void illegalWeakETagWithoutLeadingQuote() {
String etag = "W/v2.6\"";
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(etag));
}

@Test
void ifMatch() {
String ifMatch = "\"v2.6\"";
Expand Down

0 comments on commit f78b09f

Please sign in to comment.