hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1078804 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
Date Mon, 07 Mar 2011 15:09:03 GMT
Author: olegk
Date: Mon Mar  7 15:09:03 2011
New Revision: 1078804

URL: http://svn.apache.org/viewvc?rev=1078804&view=rev
Log:
HTTPCLIENT-1066: Handling of multiple consecutive slashes in the URI path component

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1078804&r1=1078803&r2=1078804&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Mar  7 15:09:03 2011
@@ -1,5 +1,11 @@
 Changes since 4.1
 
+* [HTTPCLIENT-1066] Changed the way URIUtils#rewriteURI handles multiple consecutive slashes
in the
+  URI path component: multiple leading slashes will be replaced by one slash in order to
avoid
+  confusion with the authority component. The remaining content of the path will not be modified.

+  (also see HTTPCLIENT-929).   
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1061] Fixed critical bug causing Proxy-Authorization header to be sent to the
target
   host when tunneling requests through a proxy server that requires authentication.
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java?rev=1078804&r1=1078803&r2=1078804&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
Mon Mar  7 15:09:03 2011
@@ -148,25 +148,20 @@ public class URIUtils {
         }
     }
 
-    private static String normalizePath(final String path) {
+    private static String normalizePath(String path) {
         if (path == null) {
             return null;
         }
-        StringBuilder buffer = new StringBuilder(path.length());
-        boolean gotslash = false;
-        for (int i = 0; i < path.length(); i++) {
-            char ch = path.charAt(i);
-            if (ch == '/') {
-                if (!gotslash) {
-                    buffer.append(ch);
-                    gotslash = true;
-                }
-            } else {
-                buffer.append(ch);
-                gotslash = false;
+        int n = 0;
+        for (; n < path.length(); n++) {
+            if (path.charAt(n) != '/') {
+                break;
             }
         }
-        return buffer.toString();
+        if (n > 1) {
+            path = path.substring(n - 1);
+        }
+        return path;
     }
 
     /**

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java?rev=1078804&r1=1078803&r2=1078804&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
Mon Mar  7 15:09:03 2011
@@ -61,7 +61,7 @@ public class TestURIUtils {
     @Test
     public void testRewite03() throws Exception {
         URI uri = URI.create("http://thishost//stuff///morestuff");
-        Assert.assertEquals("/stuff/morestuff", URIUtils.rewriteURI(uri, null).toString());
+        Assert.assertEquals("/stuff///morestuff", URIUtils.rewriteURI(uri, null).toString());
     }
 
     @Test
@@ -79,6 +79,12 @@ public class TestURIUtils {
     }
 
     @Test
+    public void testRewite06() throws Exception {
+        URI uri = URI.create("http://thishost//////////////stuff/");
+        Assert.assertEquals("/stuff/", URIUtils.rewriteURI(uri, null).toString());
+    }
+
+    @Test
     public void testResolve00() {
         Assert.assertEquals("g:h", URIUtils.resolve(this.baseURI, "g:h").toString());
     }



Mime
View raw message