Import upstream change: HttpCookie.domainMatches("hostname.local", "hostname") should return true
Upstream change:
7023713: HttpCookie.domainMatches("hostname.local", "hostname") should return true
Reviewed-by: chegar
Contributed-by: zhouyx@linux.vnet.ibm.com
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/5c1f90dd0405
Bug: 29067535
Test: org.apache.harmony.tests.java.net.HttpCookieTest#test_DomainMatches
Change-Id: I47b59a35e89ddb488554c712a58f645785409bc6
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java
index e8d2ba9..3282616 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java
@@ -164,6 +164,10 @@
match = HttpCookie.domainMatches(null, "b.a.AJAX.com");
assertFalse(match);
+
+ // JDK-7023713
+ match = HttpCookie.domainMatches("hostname.local", "hostname");
+ assertTrue(match);
}
/**
diff --git a/ojluni/src/main/java/java/net/HttpCookie.java b/ojluni/src/main/java/java/net/HttpCookie.java
index 3c80f29..295c926 100755
--- a/ojluni/src/main/java/java/net/HttpCookie.java
+++ b/ojluni/src/main/java/java/net/HttpCookie.java
@@ -693,10 +693,14 @@
&& (embeddedDotInDomain == -1 || embeddedDotInDomain == domain.length() - 1))
return false;
- // if the host name contains no dot and the domain name is .local
+ // if the host name contains no dot and the domain name
+ // is .local or host.local
int firstDotInHost = host.indexOf('.');
- if (firstDotInHost == -1 && isLocalDomain)
+ if (firstDotInHost == -1 &&
+ (isLocalDomain ||
+ domain.equalsIgnoreCase(host + ".local"))) {
return true;
+ }
int domainLength = domain.length();
int lengthDiff = host.length() - domainLength;