Fix bug in URIBuilder#isPathEmpty method to verify if encodedPath is an empty string

This commit is contained in:
Varun Nandi 2019-04-23 16:35:15 -07:00
parent 70585fc2d5
commit 8f6df7259a
2 changed files with 14 additions and 2 deletions

View File

@ -34,7 +34,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.http.Consts;
import org.apache.http.NameValuePair;
import org.apache.http.conn.util.InetAddressUtils;
@ -521,7 +520,8 @@ public class URIBuilder {
* @since 4.5.8
*/
public boolean isPathEmpty() {
return (this.pathSegments == null || this.pathSegments.isEmpty()) && this.encodedPath == null;
return (this.pathSegments == null || this.pathSegments.isEmpty()) &&
(this.encodedPath == null || this.encodedPath.isEmpty());
}
/**

View File

@ -34,6 +34,7 @@ import org.apache.http.conn.routing.HttpRoute;
import org.junit.Assert;
import org.junit.Test;
import static org.apache.http.client.utils.URIUtils.DROP_FRAGMENT;
import static org.apache.http.client.utils.URIUtils.DROP_FRAGMENT_AND_NORMALIZE;
import static org.apache.http.client.utils.URIUtils.NORMALIZE;
@ -83,6 +84,17 @@ public class TestURIUtils {
URI.create("http://thishost/Fragment_identifier%23Examples")).toString());
}
@Test
public void testRewriteWithEmptyPath() throws Exception {
final HttpHost target = new HttpHost("thathost", -1);
Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
URI.create("http://thathost"), target, DROP_FRAGMENT_AND_NORMALIZE).toString());
Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
URI.create("http://thathost"), target, DROP_FRAGMENT).toString());
}
@Test
public void testRewritePort() throws Exception {
HttpHost target = new HttpHost("thathost", 8080); // port should be copied