7023713: HttpCookie.domainMatches("hostname.local", "hostname") should return true
authorchegar
Mon, 22 Aug 2011 14:09:28 +0100
changeset 10352 edde66d3118f
parent 10351 e2cef0ef9e28
child 10354 5257798c26d0
7023713: HttpCookie.domainMatches("hostname.local", "hostname") should return true Reviewed-by: chegar Contributed-by: zhouyx@linux.vnet.ibm.com
jdk/src/share/classes/java/net/HttpCookie.java
jdk/test/java/net/CookieHandler/TestHttpCookie.java
--- a/jdk/src/share/classes/java/net/HttpCookie.java	Mon Aug 22 11:35:11 2011 +0100
+++ b/jdk/src/share/classes/java/net/HttpCookie.java	Mon Aug 22 14:09:28 2011 +0100
@@ -748,10 +748,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;
--- a/jdk/test/java/net/CookieHandler/TestHttpCookie.java	Mon Aug 22 11:35:11 2011 +0100
+++ b/jdk/test/java/net/CookieHandler/TestHttpCookie.java	Mon Aug 22 14:09:28 2011 +0100
@@ -362,12 +362,13 @@
         eq(c1, c2, false);
 
         header("Test domainMatches()");
-        dm(".foo.com",  "y.x.foo.com",      false);
-        dm(".foo.com",  "x.foo.com",        true);
-        dm(".com",      "whatever.com",     false);
-        dm(".com.",     "whatever.com",     false);
-        dm(".ajax.com", "ajax.com",         true);
-        dm(".local",    "example.local",    true);
+        dm(".foo.com",      "y.x.foo.com",      false);
+        dm(".foo.com",      "x.foo.com",        true);
+        dm(".com",          "whatever.com",     false);
+        dm(".com.",         "whatever.com",     false);
+        dm(".ajax.com",     "ajax.com",         true);
+        dm(".local",        "example.local",    true);
+        dm("example.local", "example",          true);
 
         // bug 6277808
         testCount++;