Skip to content

Commit b53df0b

Browse files
author
Sheridan C Rawlins
committed
Also include a test and fix to createUri that bails if the host is empty #560.
1 parent fca3613 commit b53df0b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public final static URI createUri(String u) {
6161
return URI.create(u + "/");
6262
}
6363

64+
if (uri.getHost() == null) {
65+
throw new IllegalArgumentException("The URI host, of the URI " + uri + ", must be non-null.");
66+
}
67+
6468
return uri;
6569
}
6670

api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.asynchttpclient.util;
1414

1515
import static org.testng.Assert.assertEquals;
16+
import static org.testng.Assert.fail;
1617

1718
import org.testng.annotations.Test;
1819

@@ -44,4 +45,14 @@ public void getRedirectUriShouldHandleRelativeLocation() {
4445
URI uri = AsyncHttpProviderUtils.getRedirectUri(URI.create("http://www.ebay.de"), url);
4546
assertEquals(uri.toString(), "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505");
4647
}
48+
49+
@Test(groups = "fast")
50+
public void createUriFailsWithBadHost() throws Exception {
51+
try {
52+
final String BAD_HOST_URL = "http:///";
53+
URI uri = AsyncHttpProviderUtils.createUri(BAD_HOST_URL);
54+
fail("Expected IllegalArgumentException for url: " + BAD_HOST_URL);
55+
} catch (IllegalArgumentException ex) {
56+
}
57+
}
4758
}

0 commit comments

Comments
 (0)