hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1779735 - in /httpcomponents/httpclient/branches/4.5.x/httpclient/src: main/java/org/apache/http/client/utils/URIBuilder.java test/java/org/apache/http/client/utils/TestURIBuilder.java
Date Sat, 21 Jan 2017 14:43:44 GMT
Author: olegk
Date: Sat Jan 21 14:43:44 2017
New Revision: 1779735

URL: http://svn.apache.org/viewvc?rev=1779735&view=rev
Log:
HTTPCLIENT-1803: Improved handling of malformed paths by URIBuilder

Modified:
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java?rev=1779735&r1=1779734&r2=1779735&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
Sat Jan 21 14:43:44 2017
@@ -493,7 +493,7 @@ public class URIBuilder {
     private static String normalizePath(final String path) {
         String s = path;
         if (s == null) {
-            return null;
+            return "/";
         }
         int n = 0;
         for (; n < s.length(); n++) {
@@ -504,6 +504,9 @@ public class URIBuilder {
         if (n > 1) {
             s = s.substring(n - 1);
         }
+        if (!s.startsWith("/")) {
+            s = "/" + s;
+        }
         return s;
     }
 

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java?rev=1779735&r1=1779734&r2=1779735&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
Sat Jan 21 14:43:44 2017
@@ -292,4 +292,11 @@ public class TestURIBuilder {
         return parameters;
     }
 
+    @Test
+    public void testMalformedPath() throws Exception {
+        final String path = "@notexample.com/mypath";
+        final URI uri = new URIBuilder(path).setHost("example.com").build();
+        Assert.assertEquals("example.com", uri.getHost());
+    }
+
 }



Mime
View raw message