Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3D93C17D06 for ; Wed, 23 Sep 2015 21:17:06 +0000 (UTC) Received: (qmail 24555 invoked by uid 500); 23 Sep 2015 21:17:06 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 24457 invoked by uid 500); 23 Sep 2015 21:17:06 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 24434 invoked by uid 99); 23 Sep 2015 21:17:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Sep 2015 21:17:05 +0000 Date: Wed, 23 Sep 2015 21:17:05 +0000 (UTC) From: "Bernd Eckenfels (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (VFS-524) The uri include ipv6 address can't be parsed out correctly MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/VFS-524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14905278#comment-14905278 ] Bernd Eckenfels commented on VFS-524: ------------------------------------- I think parsing is only half the work, the URLs should also be created with []. This testcase here should work (using a named interface scope and a non-default port): {code} name = (GenericFileName) urlParser.parseUri(null, null, "ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330%em4]:2222/test"); assertEquals("2002:9ba:b4e:6:a052:5792:c0c9:2330%em4", name.getHostName()); assertEquals(2222, name.getPort()); assertEquals("ftp://[2002:9ba:b4e:6:a052:5792:c0c9:2330%em4]:2222/test", name.getURI()); {code} getURI() could skip the brackets when it does not need port or scope, but I think adding it in all cases is better. I think it should not be returned by getHostName() (even when it makes the thing more complicated). > 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 > > Attachments: VFS-524-v2.patch > > > 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)