[
https://issues.apache.org/jira/browse/HTTPCORE-787?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18034497#comment-18034497
]
Jared Jacobs commented on HTTPCORE-787:
---------------------------------------
[~olegk], thanks for the prompt response.
The
[doc|https://hc.apache.org/httpcomponents-core-5.3.x/current/httpcore5/apidocs/org/apache/hc/core5/net/URIBuilder.html#getPath--]
for {{getPath}} says just:
{quote}Gets the path.
{quote}
…so whether it “does exactly what it is expected to do” may vary from person to
person. If it behaved as I expected it to, I wouldn’t have filed this issue.
I hope you will consider clarifying the method’s doc. The
[doc|https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URI.html#getPath()]
on {{java.net.URI.getPath()}} is much clearer, for example:
{quote}Returns the decoded path component of this URI.
The string returned by this method is equal to that returned by the
{{getRawPath}} method except that all sequences of escaped octets are decoded.
{quote}
Regarding your disdain for “Those people who need silliness like '/' character
in their path segments”, please consider the fact that many people use Apache
HTTP libraries as _clients_ of APIs they didn’t design, so they have no say in
what characters occur in path segments.
> URIBuilder.getPath() should escape each segment
> -----------------------------------------------
>
> Key: HTTPCORE-787
> URL: https://issues.apache.org/jira/browse/HTTPCORE-787
> Project: HttpComponents HttpCore
> Issue Type: Bug
> Components: HttpCore
> Affects Versions: 5.3.6
> Reporter: Jared Jacobs
> Priority: Major
>
> When a path contains escaped characters, {{getPath()}} incorrectly returns
> them unescaped.
> Note that {{toString()}} correctly returns the characters escaped.
> {{getPath()}} should behave like {{toString()}} in this regard.
> {code:java}
> @Test
> void testUriBuilder() throws URISyntaxException {
> String path = "/a/b/zzz%2Fzzz/c/d";
> assertEquals(new URIBuilder(path).toString(), path);
> assertEquals(new URIBuilder(path).getPathSegments(), List.of("a", "b",
> "zzz/zzz", "c", "d"));
> assertEquals(new URIBuilder(path).getPath(), path);
> } {code}
> The last {{assertEquals}} above fails with:
> {quote}{{Expected: /a/b/zzz%2Fzzz/c/d}}
> {{Actual: /a/b/zzz/zzz/c/d}}
> {quote}
> As you can see, failing to escape path segments can break a URL by, for
> example, introducing new path segments by subdividing a path segment with new
> (unescaped) slashes.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]