Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,9 @@ public URIBuilder appendPathSegments(final List<String> pathSegments) {
if (pathSegments != null && !pathSegments.isEmpty()) {
if (this.pathSegments == null) {
this.pathSegments = new ArrayList<>();
} else if (!this.pathSegments.isEmpty() && this.pathSegments.get(this.pathSegments.size() - 1).isEmpty()) {
// Path ending with a slash: append after the slash instead of producing '//'
this.pathSegments.remove(this.pathSegments.size() - 1);
}
this.pathSegments.addAll(pathSegments);
this.encodedSchemeSpecificPart = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,26 @@ void testAppendNullSegmentsList() throws Exception {
Assertions.assertEquals(URI.create("http://myhost"), uri);
}

@Test
void testAppendToPathWithTrailingSlash() throws Exception {
Assertions.assertEquals(URI.create("https://somehost/api"),
new URIBuilder("https://somehost/").appendPath("api").build());
Assertions.assertEquals(URI.create("https://somehost/api/v1/resources/idA"),
new URIBuilder("https://somehost/api/").appendPath("v1/resources").appendPath("idA").build());
Assertions.assertEquals(URI.create("https://somehost/api/v1/"),
new URIBuilder("https://somehost").setPath("/api/").appendPath("/v1/").build());
Assertions.assertEquals(URI.create("https://somehost/api/"),
new URIBuilder("https://somehost/api/").appendPath("/").build());
}

@Test
void testAppendSegmentsToPathWithTrailingSlash() throws Exception {
Assertions.assertEquals(URI.create("http://myhost/api/v3/products"),
new URIBuilder("http://myhost/").appendPathSegments("api", "v3", "products").build());
Assertions.assertEquals(URI.create("http://myhost/api/v3/customers"),
new URIBuilder("http://myhost/api/").appendPathSegments(Arrays.asList("v3", "customers")).build());
}

@Test
void testNoAuthorityAndPathSegments() throws Exception {
final URI uri = new URIBuilder()
Expand Down