Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ private RawCookie parseCookie(final CharSequence buffer,
}
}
}
if (!Cookie.DOMAIN_ATTR.equals(paramName) || !TextUtils.isBlank(paramValue)) {
// Ignore empty 'Domain' attributes and those ending with '.' so the cookie stays host-only
if (!Cookie.DOMAIN_ATTR.equals(paramName)
|| !TextUtils.isBlank(paramValue) && !paramValue.endsWith(".")) {
attribMap.put(paramName, paramValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ void testEmptyDomainAttributeIgnored() throws Exception {
Assertions.assertEquals("example.com", cookieWithEmptyDomainFirst.getDomain());
}

@Test
void testTrailingDotDomainAttributeIgnored() throws Exception {
final RFC6265CookieSpec cookiespec = new RFC6265StrictSpec();
final CookieOrigin origin = new CookieOrigin("example.com", 80, "/", false);

final Cookie hostOnlyCookie = cookiespec.parse(
new BasicHeader("Set-Cookie", "name=value; Domain=example.com."), origin).get(0);
cookiespec.validate(hostOnlyCookie, origin);
Assertions.assertEquals("example.com", hostOnlyCookie.getDomain());
Assertions.assertFalse(hostOnlyCookie.containsAttribute(Cookie.DOMAIN_ATTR));
Assertions.assertTrue(cookiespec.match(hostOnlyCookie, origin));
Assertions.assertFalse(cookiespec.match(hostOnlyCookie,
new CookieOrigin("sub.example.com", 80, "/", false)));

final Cookie cookie = cookiespec.parse(
new BasicHeader("Set-Cookie", "name=value; Domain=example.com; Domain=foo."), origin).get(0);
Assertions.assertEquals("example.com", cookie.getAttribute(Cookie.DOMAIN_ATTR));
}

@Test
void testNoArgSpecsUsePublicSuffixMatcher() throws Exception {
final CookieOrigin publicSuffixOrigin = new CookieOrigin("foo.com", 80, "/", false);
Expand Down
Loading