You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2006/06/21 12:51:00 UTC

svn commit: r415958 - in /jakarta/commons/proper/httpclient/trunk: release_notes.txt src/java/org/apache/commons/httpclient/URI.java src/test/org/apache/commons/httpclient/TestURI.java

Author: olegk
Date: Wed Jun 21 03:51:00 2006
New Revision: 415958

URL: http://svn.apache.org/viewvc?rev=415958&view=rev
Log:
[HTTPCLIENT-587] derelativizing of relative URIs with a scheme is incorrect

Contributed by Gordon Mohr <gojomo at archive.org>
Reviewed by Oleg Kalnichevski and Roland Weber

Modified:
    jakarta/commons/proper/httpclient/trunk/release_notes.txt
    jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/URI.java
    jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java

Modified: jakarta/commons/proper/httpclient/trunk/release_notes.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/release_notes.txt?rev=415958&r1=415957&r2=415958&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/release_notes.txt (original)
+++ jakarta/commons/proper/httpclient/trunk/release_notes.txt Wed Jun 21 03:51:00 2006
@@ -1,5 +1,8 @@
 Changes toward 3.1 
 
+ * [HTTPCLIENT-587] - Fixed incorrect derelativizing of relative URIs with a scheme
+           Contributed by Gordon Mohr <gojomo at archive.org>
+           
  * [HTTPCLIENT-494] - Invalid redirect location now causes a protocol exception
            Contributed by Oleg Kalnichevski <olegk at apache.org>
            

Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/URI.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/URI.java?rev=415958&r1=415957&r2=415958&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/URI.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/URI.java Wed Jun 21 03:51:00 2006
@@ -33,6 +33,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.util.Arrays;
 import java.util.Locale;
 import java.util.BitSet;
 import java.util.Hashtable;
@@ -512,6 +513,7 @@
         if (base._scheme != null) {
             this._scheme = base._scheme;
             this._authority = base._authority;
+            this._is_net_path = base._is_net_path; 
         }
         if (base._is_opaque_part || relative._is_opaque_part) {
             this._scheme = base._scheme;
@@ -522,7 +524,9 @@
             this.setURI();
             return;
         }
-        if (relative._scheme != null) {
+        boolean schemesEqual = Arrays.equals(base._scheme,relative._scheme);
+        if (relative._scheme != null 
+                && (!schemesEqual  || relative._authority != null)) {
             this._scheme = relative._scheme;
             this._is_net_path = relative._is_net_path;
             this._authority = relative._authority;
@@ -565,7 +569,8 @@
             this._path = relative._path;
         }
         // resolve the path and query if necessary
-        if (relative._scheme == null && relative._authority == null) {
+        if (relative._authority == null 
+            && (relative._scheme == null || schemesEqual)) {
             if ((relative._path == null || relative._path.length == 0)
                 && relative._query == null) {
                 // handle a reference to the current document, see RFC 2396 

Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java?rev=415958&r1=415957&r2=415958&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java Wed Jun 21 03:51:00 2006
@@ -278,4 +278,22 @@
         }
     }    
     
+    /**
+     * Verify proper handling of relative URIs which have a scheme. 
+     * See bug http://issues.apache.org/jira/browse/HTTPCLIENT-587
+     * 
+     * @throws Exception
+     */
+    public void testRelativeWithScheme() throws Exception {
+        URI base = new URI("http://www.example.com/some/path", true);
+        URI rel1 = new URI("http:", true);
+        URI rel2 = new URI("http:foo", true);
+        URI rel3 = new URI("http:../../bar", true);
+        URI derel1 = new URI(base, rel1);
+        assertEquals("http://www.example.com/some/path",derel1.toString());
+        URI derel2 = new URI(base, rel2);
+        assertEquals("http://www.example.com/some/foo",derel2.toString());
+        URI derel3 = new URI(base,rel3);
+        assertEquals("http://www.example.com/bar",derel3.toString());
+    }
 }



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