[
https://issues.apache.org/jira/browse/HTTPCLIENT-1960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16740328#comment-16740328
]
Raymond Cuenen commented on HTTPCLIENT-1960:
--------------------------------------------
{quote}Why?
{quote}
RFC 3986: The path component of a URI consists of a sequence of path segments
separated by a slash. If an authority component is present, then the path
component must either be empty or begin with a slash. If an authority component
is absent, then the path cannot begin with an empty segment, that is with two
slashes.
So if your path represents an absolute (file-)path; beginning with a slash,
there is no other way to represent the first slash of the path other then
URI-encoded (%2F). When using two slashes makes the first part of the path the
authority component (when no authority present), or inserts an empty path
segment into the path representation (when an authority is present).
> URIBuilder does not handle absolute path values
> -----------------------------------------------
>
> Key: HTTPCLIENT-1960
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1960
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient (async), HttpClient (classic)
> Affects Versions: 4.5.5
> Reporter: Raymond Cuenen
> Priority: Major
>
> If original path startsWith '/' it is removed by normalizePath; in that case
> it should be added again URI-encoded. For example: A path value of
> '/etc/motd' becomes:
> {code:java}
> ftp://[email protected]/etc/motd{code}
> while it should be:
> {code:java}
> ftp://[email protected]/%2Fetc/motd{code}
> Only when the path value is 'etc/motd' is should become
> "ftp://[email protected]/etc/motd"
>
> Fix for this issue in URIBuilder.java:
> {noformat}
> private String buildString() {
> ...
> if (this.encodedPath != null) {
> sb.append(normalizePath(this.encodedPath, sb.length() == 0));
> } else if (this.path != null) {
> String encodedPath = encodePath(normalizePath(this.path, sb.length()
> == 0));
> // Start fix for paths starting with '/'
> // If original path startsWith '/' it is removed by normalizePath; in
> that case it should be added again URI-encoded.
> if (this.path.startsWith("/")) {
> encodedPath = "/%2F" + encodedPath.substring(1);
> }
> // End fix
> sb.append(encodedPath);
> }
> ...
> }{noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]