hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1353445 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils: URIBuilder.java URIUtils.java
Date Mon, 25 Jun 2012 09:53:08 GMT
Author: sebb
Date: Mon Jun 25 09:53:07 2012
New Revision: 1353445

URL: http://svn.apache.org/viewvc?rev=1353445&view=rev
Log:
HTTPCLIENT-1195 - URIBuilder-created query strings are double-escaped
Move normalization from URIUtils to URIBuilder so encodedPath is not dropped

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java?rev=1353445&r1=1353444&r2=1353445&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
Mon Jun 25 09:53:07 2012
@@ -115,9 +115,9 @@ public class URIBuilder {
                 }
             }
             if (this.encodedPath != null) {
-                sb.append(this.encodedPath);
+                sb.append(normalizePath(this.encodedPath));
             } else if (this.path != null) {
-                sb.append(encodePath(this.path));
+                sb.append(encodePath(normalizePath(this.path)));
             }
             if (this.encodedQuery != null) {
                 sb.append("?").append(this.encodedQuery);
@@ -217,7 +217,7 @@ public class URIBuilder {
      * Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.
      */
     public URIBuilder setPath(final String path) {
-        this.path = path;
+        this.path = normalizePath(path);
         this.encodedSchemeSpecificPart = null;
         this.encodedPath = null;
         return this;
@@ -326,4 +326,20 @@ public class URIBuilder {
         return buildString();
     }
 
+    private static String normalizePath(String path) {
+        if (path == null) {
+            return null;
+        }
+        int n = 0;
+        for (; n < path.length(); n++) {
+            if (path.charAt(n) != '/') {
+                break;
+            }
+        }
+        if (n > 1) {
+            path = path.substring(n - 1);
+        }
+        return path;
+    }
+
 }

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=1353445&r1=1353444&r2=1353445&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 Jun 25 09:53:07 2012
@@ -141,29 +141,12 @@ public class URIUtils {
             uribuilder.setHost(null);
             uribuilder.setPort(-1);
         }
-        uribuilder.setPath(normalizePath(uribuilder.getPath()));
         if (dropFragment) {
             uribuilder.setFragment(null);
         }
         return uribuilder.build();
     }
 
-    private static String normalizePath(String path) {
-        if (path == null) {
-            return null;
-        }
-        int n = 0;
-        for (; n < path.length(); n++) {
-            if (path.charAt(n) != '/') {
-                break;
-            }
-        }
-        if (n > 1) {
-            path = path.substring(n - 1);
-        }
-        return path;
-    }
-
     /**
      * A convenience method for
      * {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the



Mime
View raw message