[
https://issues.apache.org/jira/browse/VFS-524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14494042#comment-14494042
]
Philipp Brügger commented on VFS-524:
-------------------------------------
The RFC 3986 [RFC 3986|http://tools.ietf.org/html/rfc3986] defines the usage
of IPv6 adresses inside of brackets [].
The following change of the method adds the extraction of IPv6 adresses:
{code:title=HostFileNameParser.java|borderStyle=solid}
protected String extractHostName(final StringBuilder name)
{
final int maxlen = name.length();
int startPos = 0;
int endPos = 0;
if(name.charAt(0) == '['){
//RFC-3986 IPv6address
startPos = 1;
for (; endPos < maxlen; endPos++)
{
final char ch = name.charAt(endPos);
if (ch == ']')
{
break;
}
}
}
else {
for (; endPos < maxlen; endPos++)
{
final char ch = name.charAt(endPos);
if (ch == '/' || ch == ';' || ch == '?' || ch == ':'
|| ch == '@' || ch == '&' || ch == '=' || ch == '+'
|| ch == '$' || ch == ',')
{
break;
}
}
}
if (endPos == 0)
{
return null;
}
final String hostname = name.substring(startPos, endPos);
if(name.charAt(0) == '['){
//RFC-3986 IPv6address remove ']' at the end
name.delete(0, endPos+1);
}
else
{
name.delete(0, endPos);
}
return hostname;
}
{code}
Please add this feature of supporting IPv6 to the SVN or schedule this feature
for a future release.
> The uri include ipv6 address can't be parsed out correctly
> ----------------------------------------------------------
>
> Key: VFS-524
> URL: https://issues.apache.org/jira/browse/VFS-524
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 2.0
> Reporter: Alex
> Fix For: 2.1
>
>
> I am using apache commons vfs2 to read and download file in ipv6 enviroment,
> but it seems can't parse out ipv6 address correctly
> The URI is just like:
> ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330]/test
> The error message:
> Invalid absolute URI "ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330]/test".
> Caused by : Expecting / to follow the hostname in URI
> "ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330]/test".
> Deep into the code, I found the root cause is that HostFileNameParser's
> extractHostName can't parse out the host name correctly
> {noformat}
> /**
> * Extracts the hostname from a URI. The scheme://userinfo@ part has
> * been removed.
> */
> protected String extractHostName(final StringBuilder name)
> {
> final int maxlen = name.length();
> int pos = 0;
> for (; pos < maxlen; pos++)
> {
> final char ch = name.charAt(pos);
> if (ch == '/' || ch == ';' || ch == '?' || ch == ':'
> || ch == '@' || ch == '&' || ch == '=' || ch == '+'
> || ch == '$' || ch == ',')
> {
> break;
> }
> }
> if (pos == 0)
> {
> return null;
> }
> final String hostname = name.substring(0, pos);
> name.delete(0, pos);
> return hostname;
> }
> {noformat}
> From the code, we are able to know it will parse out the host name by colon,
> but for ipv6, it will get a wrong host name
> There is the same problem with the other protocol like sftp and cifs
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)