HttpCookie.domainMatches("hostname.local", "hostname") return false
Chris Hegarty
chris.hegarty at oracle.com
Mon Aug 22 06:18:02 PDT 2011
Here is the JDK8 changeset, to close the loop on this one. Note, the
change is slightly different to the patch posted.
Changeset: 5c1f90dd0405
Author: chegar
Date: 2011-08-22 14:09 +0100
URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/5c1f90dd0405
7023713: HttpCookie.domainMatches("hostname.local", "hostname") should
return true
Reviewed-by: chegar
Contributed-by: zhouyx at linux.vnet.ibm.com
! src/share/classes/java/net/HttpCookie.java
! test/java/net/CookieHandler/TestHttpCookie.java
-Chris.
On 22/08/2011 07:21, Sean Chou wrote:
> Thank you very much!
>
> 2011/8/19 Chris Hegarty <chris.hegarty at oracle.com
> <mailto:chris.hegarty at oracle.com>>
>
> Hi Sean,
>
> I submitted a JPRT job with you patch. If all builds and tests are
> successful I'll push this change for you.
>
> diff -r 46b53f80ab0a src/share/classes/java/net/__HttpCookie.java
> --- a/src/share/classes/java/net/__HttpCookie.java Fri Aug 19
> 10:55:05 2011 +0100
> +++ b/src/share/classes/java/net/__HttpCookie.java Fri Aug 19
> 15:16:36 2011 +0100
> @@ -751,6 +751,11 @@ public final class HttpCookie implements
> // if the host name contains no dot and the domain name is
> .local
>
> int firstDotInHost = host.indexOf('.');
> if (firstDotInHost == -1 && isLocalDomain)
> + return true;
> +
> + // if the host name contains no dot and the domain name is
> "host.local"
> + if (firstDotInHost == -1 &&
> + domain.equalsIgnoreCase(host + ".local"))
> return true;
>
> int domainLength = domain.length();
> diff -r 46b53f80ab0a test/java/net/CookieHandler/__TestHttpCookie.java
> --- a/test/java/net/CookieHandler/__TestHttpCookie.java Fri Aug 19
> 10:55:05 2011 +0100
> +++ b/test/java/net/CookieHandler/__TestHttpCookie.java Fri Aug 19
> 15:16:36 2011 +0100
> @@ -362,12 +362,13 @@ public class TestHttpCookie {
> eq(c1, c2, false);
>
> header("Test domainMatches()");
> - dm(".foo.com <http://foo.com>", "y.x.foo.com
> <http://y.x.foo.com>", false);
> - dm(".foo.com <http://foo.com>", "x.foo.com
> <http://x.foo.com>", true);
> - dm(".com", "whatever.com <http://whatever.com>", false);
> - dm(".com.", "whatever.com <http://whatever.com>", false);
>
> - dm(".ajax.com <http://ajax.com>", "ajax.com
> <http://ajax.com>", true);
> - dm(".local", "example.local", true);
> + dm(".foo.com <http://foo.com>", "y.x.foo.com
> <http://y.x.foo.com>", false);
> + dm(".foo.com <http://foo.com>", "x.foo.com
> <http://x.foo.com>", true);
> + dm(".com", "whatever.com <http://whatever.com>", false);
> + dm(".com.", "whatever.com <http://whatever.com>", false);
>
> + dm(".ajax.com <http://ajax.com>", "ajax.com
> <http://ajax.com>", true);
> + dm(".local", "example.local", true);
> + dm("example.local", "example", true);
>
> // bug 6277808
> testCount++;
>
> -Chris.
>
>
>
> On 04/08/2011 08:09, Sean Chou wrote:
>
> Hi all,
>
> I checked with java8, this problem still exists; and I
> checked the
> patch, it is still working.
> The bug was filed with id 7023713 for java7, and the patch is
> here. So,
> would anyone like to
> take a look at it again? Thanks.
>
> 2011/2/22 Sean Chou <zhouyx at linux.vnet.ibm.com
> <mailto:zhouyx at linux.vnet.ibm.com>
> <mailto:zhouyx at linux.vnet.ibm.__com
> <mailto:zhouyx at linux.vnet.ibm.com>>>
>
>
> Hi,
> I find that HttpCookie.domainMatches("__hostname.local",
> "hostname") returns false, which may be a bug.
> According to spec, the effective host name of "hostname" is
> "hostname.local", which is string
> exactly the same with the first parameter. Thus the method
> should
> return true for this invocation.
>
> I attached the simple testcase here:
> // Testcase
> import java.net.HttpCookie;
>
> public class DomainMatchTest{
>
> public static void main(String args[]){
> // "true" should be printed, but get "false".
>
> System.out.println(HttpCookie.__domainMatches("hostname.local"__,
> "hostname"));
> }
>
> }
> // End of testcase
>
> Any comments?
>
> --
> Best Regards,
> Sean Chou
>
>
>
>
> --
> Best Regards,
> Sean Chou
>
>
>
>
> --
> Best Regards,
> Sean Chou
>
More information about the net-dev
mailing list