Repository navigation
Conversation
…th '/'
A path that ends with '/' has an empty last segment. appendPath and
appendPathSegments added the new segments after it, so
new URIBuilder("http://host/api/").appendPath("items") built
http://host/api//items, and a base of http://host/ built
http://host//items.
The empty last segment is now replaced by the appended segments.
arturobernalg
requested changes
Nov 11, 2026
arturobernalg
left a comment
Member
There was a problem hiding this comment.
I have some concerns about changing the semantics of appendPathSegments().
RFC 3986 permits empty path segments, and consecutive slashes are not necessarily redundant. The proposed change silently removes an existing empty segment, potentially altering the intended URI.
I think path segment manipulation and path joining should remain separate concerns. Would it make more sense to handle this in the REST client rather than change the behavior of URIBuilder?
Member
|
This fix clearly belongs to the Jakarta REST client, not core. |
Member
Agreed with @ok2c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A path that ends with
/has an empty last segment, andappendPathandappendPathSegmentsadd the new segments after it. So a base URI with a trailing slash, which is how many people write one, picks up a double slash:The classic client sends these as
GET //apiandGET /api//items/42. Against an HttpCore classic server with handlers registered for/apiand/api/items/*, the first request gets421 Not authoritativeand the second gets501. With this change both get200.The Jakarta REST client in HttpClient runs into the same thing, because
RestInvocationHandleradds the resource path tobaseUriwithappendPathSegments. WithbaseUri("http://127.0.0.1:<port>/api/")and a resource atitems/{id}, the server receivesGET /api//items/42, and withbaseUri("http://127.0.0.1:<port>/")it receivesGET //items/42. Against a core built from this branch it receives/api/items/42and/items/42.ResourceIfaceScanner#joinalready drops a trailing empty segment when it joins the class and method paths, so this change bringsURIBuilderin line with it.appendPathSegmentsnow replaces an empty last segment with the appended segments. A trailing slash on the appended value is kept (/api/plus/v1/gives/api/v1/, and/api/plus/stays/api/). Appendingnullor an empty list leaves the path alone, as before.Tests:
testAppendToPathWithTrailingSlashandtestAppendSegmentsToPathWithTrailingSlashinTestURIBuilder. Without the change they fail withexpected: <https://somehost/api> but was: <https://somehost//api>andexpected: <http://myhost/api/v3/products> but was: <http://myhost//api/v3/products>. With it, all 82 tests inTestURIBuilderand the 141 tests inorg.apache.hc.core5.netpass, and checkstyle passes. I also ran the 84 tests ofhttpclient5-jakarta-rest-client(HttpClient master) against a core built from this branch, and they pass.All of this ran on JDK 17 only. I did not run the full HttpCore test suite.