You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by og...@apache.org on 2002/12/11 14:16:09 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestCookie.java

oglueck     2002/12/11 05:16:09

  Modified:    httpclient/src/java/org/apache/commons/httpclient/cookie
                        CookieSpecBase.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestCookie.java
  Log:
  Fixed StringIndexOutOfBoundsException and added test case.
  
  Reported by: Christopher Lenz
  Patch contributed by: Michael Becke
  
  Revision  Changes    Path
  1.3       +4 -2      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CookieSpecBase.java	9 Dec 2002 12:48:40 -0000	1.2
  +++ CookieSpecBase.java	11 Dec 2002 13:16:09 -0000	1.3
  @@ -501,14 +501,16 @@
       private static boolean pathMatch(final String path, final String topmostPath)
       {
           boolean match = path.startsWith( topmostPath );
  -        if (match) {
  +        
  +        // if there is a match and these values are not exactly the same we have
  +        // to make sure we're not matcing "/foobar" and "/foo"
  +        if ( match && path.length() != topmostPath.length() ) {
               if (!topmostPath.endsWith(PATH_DELIM)) {
                   match = (path.charAt(topmostPath.length()) == PATH_DELIM_CHAR);
               }
           }
           return match;
       }
  -
   
       /**
        * Return an array of {@link Cookie}s that should be submitted with a request with
  
  
  
  1.16      +28 -5     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java
  
  Index: TestCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestCookie.java	8 Dec 2002 06:09:46 -0000	1.15
  +++ TestCookie.java	11 Dec 2002 13:16:09 -0000	1.16
  @@ -721,7 +721,30 @@
               // Expected            
           }
       }
  -
  +    
  +    /**
  +     * Makes sure that a cookie matches with a path of the same value.
  +     */
  +    public void testMatchWithEqualPaths() {
  +        
  +        Cookie cookie = new Cookie(".test.com", "test", "1", "/test", null, false);
  +        
  +        try {
  +            boolean match = cookie.matches(
  +                "test.test.com", 
  +                80, 
  +                "/test", 
  +                false, 
  +                new Date()
  +            );
  +            
  +            assertTrue("Cookie paths did not match", match);
  +        } catch ( Exception e ) {
  +            e.printStackTrace();
  +            fail("Unexpected exception: " + e);
  +        }
  +                   
  +    }
   
       /**
        * Tests Netscape specific cookie formatting.
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>