提交 e0faaa48 编写于 作者: R Rossen Stoyanchev

Relax domain name checks in ResponseCookie

Closes gh-23924
上级 2e494419
......@@ -374,7 +374,7 @@ public final class ResponseCookie extends HttpCookie {
}
int char1 = domain.charAt(0);
int charN = domain.charAt(domain.length() - 1);
if (char1 == '.' || char1 == '-' || charN == '.' || charN == '-') {
if (char1 == '-' || charN == '.' || charN == '-') {
throw new IllegalArgumentException("Invalid first/last char in cookie domain: " + domain);
}
for (int i = 0, c = -1; i < domain.length(); i++) {
......
......@@ -85,6 +85,31 @@ public class ResponseCookieTests {
});
}
@Test
public void domainChecks() {
Arrays.asList("abc", "abc.org", "abc-def.org", "abc3.org", ".abc.org")
.forEach(domain -> ResponseCookie.from("n", "v").domain(domain).build());
Arrays.asList("-abc.org", "abc.org.", "abc.org-", "-abc.org", "abc.org-")
.forEach(domain -> {
try {
ResponseCookie.from("n", "v").domain(domain).build();
}
catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), Matchers.containsString("Invalid first/last char"));
}
});
Arrays.asList("abc..org", "abc.-org", "abc-.org")
.forEach(domain -> {
try {
ResponseCookie.from("n", "v").domain(domain).build();
}
catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), Matchers.containsString("invalid cookie domain char"));
}
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册