if (domain == null) {
return;
}
if ("".equals(domain)) {
throw new InvalidCookieDomainException(
"Domain must not be an empty string. Consider using null instead");
}
// Line-noise-tastic
if (domain.matches(".*[^:]:\\d+$")) {
domain = domain.replaceFirst(":\\d+$", "");
}
expectedDomain = expectedDomain.startsWith(".") ? expectedDomain : "." + expectedDomain;
domain = domain.startsWith(".") ? domain : "." + domain;
if (!expectedDomain.endsWith(domain)) {
throw new InvalidCookieDomainException(
String.format(
"You may only add cookies that would be visible to the current domain: %s => %s",
domain, expectedDomain));
}
}