From b40661e45ec12fb1c7ef52b1891a9b677331f48d Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 30 Apr 2014 09:32:52 +0000 Subject: [PATCH] HTTPCLIENT-1498: empty host in redirect location causes NPE git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1591221 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/http/client/utils/URIUtils.java | 2 +- .../test/java/org/apache/http/client/utils/TestURIUtils.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java index 9139995d3..d485cfe10 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java @@ -366,7 +366,7 @@ public class URIUtils { } } final String scheme = uri.getScheme(); - if (host != null) { + if (!TextUtils.isBlank(host)) { target = new HttpHost(host, port, scheme); } } diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java index 6050061a6..a0fb7eb61 100644 --- a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java +++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java @@ -229,6 +229,8 @@ public class TestURIUtils { URIUtils.extractHost(new URI("http://localhost:8080;sessionid=stuff/abcd"))); Assert.assertEquals(new HttpHost("localhost",-1), URIUtils.extractHost(new URI("http://localhost:;sessionid=stuff/abcd"))); + Assert.assertEquals(null, + URIUtils.extractHost(new URI("http://:80/robots.txt"))); } @Test