Skip to content

Commit 72459a5

Browse files
author
Stephane Landelle
committed
CookieDecoder should handle empty domain as null, close AsyncHttpClient#806
1 parent ec03713 commit 72459a5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

api/src/main/java/org/asynchttpclient/cookie/KeyValuePairsParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void parse6(String header, int nameStart, String value) {
131131
char c5 = header.charAt(nameStart + 5);
132132

133133
if (isDomain(c0, c1, c2, c3, c4, c5))
134-
domain = value;
134+
domain = value.isEmpty() ? null : value;
135135
else if (isSecure(c0, c1, c2, c3, c4, c5))
136136
secure = true;
137137
}

api/src/test/java/org/asynchttpclient/cookie/CookieDecoderTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.testng.Assert.assertEquals;
1616
import static org.testng.Assert.assertNotNull;
17+
import static org.testng.Assert.assertNull;
1718

1819
import org.testng.annotations.Test;
1920

@@ -44,4 +45,10 @@ public void testDecodeQuotedContainingEscapedQuote() {
4445
assertEquals(cookie.getValue(), "VALUE1\"");
4546
assertEquals(cookie.getRawValue(), "\"VALUE1\\\"\"");
4647
}
48+
49+
@Test(groups = "fast")
50+
public void testIgnoreEmptyDomain() {
51+
Cookie cookie = CookieDecoder.decode("sessionid=OTY4ZDllNTgtYjU3OC00MWRjLTkzMWMtNGUwNzk4MTY0MTUw;Domain=;Path=/");
52+
assertNull(cookie.getDomain());
53+
}
4754
}

0 commit comments

Comments
 (0)