Merge pull request #146 from varunnvs92/4.5.x

Fix bug in URIBuilder#isPathEmpty method
This commit is contained in:
Oleg Kalnichevski 2019-04-24 09:47:05 +02:00 committed by GitHub
commit e605ca0500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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