[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    svn commit: r409993 - in /jakarta/httpcomponents/httpclient/trunk/src:
From:       olegk () apache ! org
Date:       2006-05-28 20:22:49
Message-ID: 20060528202250.08D291A983A () eris ! apache ! org
[Download RAW message or body]

Author: olegk
Date: Sun May 28 13:22:48 2006
New Revision: 409993

URL: http://svn.apache.org/viewvc?rev=409993&view=rev
Log:
Fixed a number of problems with null domain attribute 

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java
  jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicPathHandler.java
  jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java
  jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBrowserCompatCookieAttribHandlers.java


Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java?rev=409993&r1=409992&r2=409993&view=diff
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java \
                (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java \
Sun May 28 13:22:48 2006 @@ -155,6 +155,8 @@
               domain = domain.substring(0, ndx);
             }
             cookieDomain = domain.toLowerCase();
+        } else {
+            cookieDomain = null;
         }
     }
 

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicPathHandler.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org \
/apache/http/cookie/impl/BasicPathHandler.java?rev=409993&r1=409992&r2=409993&view=diff
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicPathHandler.java \
                (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BasicPathHandler.java \
Sun May 28 13:22:48 2006 @@ -68,6 +68,9 @@
             throw new IllegalArgumentException("Cookie origin may not be null");
         }
         String targetpath = origin.getPath();
+        if (targetpath == null) {
+            targetpath = "/";
+        }
         String topmostPath = cookie.getPath();
         if (topmostPath == null) {
             topmostPath = "/";

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org \
/apache/http/cookie/impl/BrowserCompatDomainHandler.java?rev=409993&r1=409992&r2=409993&view=diff
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java \
                (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/impl/BrowserCompatDomainHandler.java \
Sun May 28 13:22:48 2006 @@ -68,26 +68,29 @@
         // request-host and domain must be identical for the cookie to sent 
         // back to the origin-server.
         String host = origin.getHost();
+        String domain = cookie.getDomain();
+        if (domain == null) {
+            throw new MalformedCookieException("Cookie domain may not be null");
+        }
         if (host.indexOf(".") >= 0) {
             // Not required to have at least two dots.  RFC 2965.
             // A Set-Cookie2 with Domain=ajax.com will be accepted.
 
             // domain must match host
-            if (!host.endsWith(cookie.getDomain())) {
-                String s = cookie.getDomain();
-                if (s.startsWith(".")) {
-                    s = s.substring(1, s.length());
+            if (!host.endsWith(domain)) {
+                if (domain.startsWith(".")) {
+                    domain = domain.substring(1, domain.length());
                 }
-                if (!host.equals(s)) { 
+                if (!host.equals(domain)) { 
                     throw new MalformedCookieException(
-                        "Illegal domain attribute \"" + cookie.getDomain() 
+                        "Illegal domain attribute \"" + domain 
                         + "\". Domain of origin: \"" + host + "\"");
                 }
             }
         } else {
-            if (!host.equals(cookie.getDomain())) {
+            if (!host.equals(domain)) {
                 throw new MalformedCookieException(
-                    "Illegal domain attribute \"" + cookie.getDomain() 
+                    "Illegal domain attribute \"" + domain 
                     + "\". Domain of origin: \"" + host + "\"");
             }
         }

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBrowserCompatCookieAttribHandlers.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org \
/apache/http/cookie/impl/TestBrowserCompatCookieAttribHandlers.java?rev=409993&r1=409992&r2=409993&view=diff
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBrowserCompatCookieAttribHandlers.java \
                (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestBrowserCompatCookieAttribHandlers.java \
Sun May 28 13:22:48 2006 @@ -128,6 +128,19 @@
         h.validate(cookie, origin);
     }
 
+    public void testBrowserCompatDomainValidate4() throws Exception {
+        Cookie cookie = new Cookie("name", "value"); 
+        CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false); 
+        CookieAttributeHandler h = new BrowserCompatDomainHandler();
+        
+        cookie.setDomain(null);
+        try {
+            h.validate(cookie, origin);
+            fail("MalformedCookieException should have been thrown");
+        } catch (MalformedCookieException ex) {
+            // expected
+        }
+    }
     
     public void testBrowserCompatDomainMatch1() throws Exception {
         Cookie cookie = new Cookie("name", "value"); 
@@ -151,6 +164,9 @@
         
         cookie.setDomain(".somedomain.com");
         assertTrue(h.match(cookie, origin));
+
+        cookie.setDomain(null);
+        assertFalse(h.match(cookie, origin));
     }
 
     public void testBrowserCompatDomainInvalidInput() throws Exception {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic