commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient Cookie.java
Date Tue, 19 Feb 2002 00:15:18 GMT
dion        02/02/18 16:15:18

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        Cookie.java
  Log:
  Various NPE fixes for bug 6513 and 6511
  
  Revision  Changes    Path
  1.13      +29 -21    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java
  
  Index: Cookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Cookie.java	14 Feb 2002 00:02:34 -0000	1.12
  +++ Cookie.java	19 Feb 2002 00:15:18 -0000	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
1.12 2002/02/14 00:02:34 dion Exp $
  - * $Revision: 1.12 $
  - * $Date: 2002/02/14 00:02:34 $
  + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v
1.13 2002/02/19 00:15:18 dion Exp $
  + * $Revision: 1.13 $
  + * $Date: 2002/02/19 00:15:18 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -87,7 +87,7 @@
    * @author Rod Waldhoff
    * @author dIon Gillard
    * @author <a href="mailto:JEvans@Cyveillance.com">John Evans</a>
  - * @version $Revision: 1.12 $ $Date: 2002/02/14 00:02:34 $
  + * @version $Revision: 1.13 $ $Date: 2002/02/19 00:15:18 $
    */
   
   public class Cookie extends NameValuePair implements Serializable, Comparator {
  @@ -228,11 +228,13 @@
        * @see #getDomain
        */
       public void setDomain(String domain) {
  -        int ndx = domain.indexOf(":");
  -        if (ndx != -1) {
  -          domain = domain.substring(0, ndx);
  +        if (domain != null) {
  +            int ndx = domain.indexOf(":");
  +            if (ndx != -1) {
  +              domain = domain.substring(0, ndx);
  +            }
  +            _domain = domain.toLowerCase();
           }
  -        _domain = domain.toLowerCase();
       }
   
   
  @@ -391,7 +393,7 @@
           //        should /foobar see the cookie? Probably not.
           return (
                   (getExpiryDate() == null || getExpiryDate().after(now)) && // only
add the cookie if it hasn't yet expired
  -                domain.endsWith(getDomain()) &&                            // and
the domain pattern matches
  +                (getDomain() == null || domain.endsWith(getDomain()) ) &&     
                      // and the domain pattern matches
                   ((getPath() == null) || (path.startsWith(getPath()))) &&   // and
the path is null or matching
                   (getSecure() ? secure : true)                              // and if the
secure flag is set, only if the request is actually secure
                  );
  @@ -499,6 +501,8 @@
        * <p>This method is implemented so a cookie can be used as a comparator for
        * a SortedSet of cookies. Specifically it's used above in the 
        * createCookieHeader method.</p>
  +     * <p>The compare only compares the path of the cookie, see section 4.3.4 
  +     * of RFC2109</p>
        */
       public int compare(Object o1, Object o2) {
           if (!(o1 instanceof Cookie)) {
  @@ -509,21 +513,25 @@
           }
           Cookie c1 = (Cookie)o1;
           Cookie c2 = (Cookie)o2;
  -        if (c1.getDomain().equals(c2.getDomain())) {
  -            if (c1.getPath().equals(c2.getPath())) {
  -                return 0; // same domain, same path
  +        if (c1.getPath() == null && c2.getPath() == null) {
  +            return 0;
  +        } else if (c1.getPath() == null) {
  +            // null is assumed to be "/"
  +            if (c2.getPath().equals("/")) {
  +                return 0;
  +            } else {
  +                return -1;
               }
  -            // same domain, different path	
  -            if (c1.getPath().length() == c2.getPath().length()) {
  -                // same length path
  -                return stringCollator.compare(c1.getPath(), c2.getPath());
  +        } else if (c2.getPath() == null) {
  +            // null is assumed to be "/"
  +            if (c1.getPath().equals("/")) {
  +                return 0;
               } else {
  -                // different length paths
  -                return c1.getPath().length() < c2.getPath().length() ? -1 : 1;
  +                return 1;
               }
  +        } else {
  +            return stringCollator.compare(c1.getPath(), c2.getPath());
           }
  -        // different domain
  -        return stringCollator.compare(c1.getDomain(), c2.getDomain());
       }
   
       /**
  @@ -733,7 +741,7 @@
               // invalid domain scope
   
               // domain must be either .local or must contain at least two dots
  -            if (!cookie.getDomain().equals("localhost")) {
  +            if (cookie.getDomain() != null && !cookie.getDomain().equals("localhost"))
{
   
                   // Not required to have at least two dots.  RFC 2965.
                   // A Set-Cookie2 with Domain=ajax.com will be accepted.
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message