[ https://issues.apache.org/jira/browse/VFS-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16366353#comment-16366353 ]
Otto Fowler commented on VFS-398: --------------------------------- Would propose the following implementation/changes UriParser : I can do a PR if the change is acceptable. {code:java} public static String extractScheme(final String uri, final StringBuilder buffer) { if (buffer != null) { buffer.setLength(0); buffer.append(uri); } // search for :/ for the scheme marker // we look for both because some filesystems // support : in the name final int maxPos = uri.length(); boolean markColon = false; for (int pos = 0; pos < maxPos; pos++) { final char ch = uri.charAt(pos); if (ch == ':') { markColon = !markColon; continue; } if (ch == '/') { // this is the second slash in :/ if (markColon) { // Found the end of the scheme final String scheme = uri.substring(0, pos - 1); if (scheme.length() <= 1 && Os.isFamily(Os.OS_FAMILY_WINDOWS)) { // This is not a scheme, but a Windows drive letter return null; } if (buffer != null) { buffer.delete(0, pos); } return scheme.intern(); } else { break; } } if(markColon) { // : not followed by a / // no scheme break; } if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { // A scheme character continue; } if (pos > 0 && ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.')) { // A scheme character (these are not allowed as the first // character of the scheme, but can be used as subsequent // characters. continue; } // Not a scheme character break; } // No scheme in URI return null; } {code} > FtpFileObject.getChildren() fails when a folder contains a file with a colon > in the name > ---------------------------------------------------------------------------------------- > > Key: VFS-398 > URL: https://issues.apache.org/jira/browse/VFS-398 > Project: Commons VFS > Issue Type: Bug > Affects Versions: 2.0 > Environment: Connecting via FTP to a host running SunOS 5.10 > Reporter: Mark Leonard > Priority: Blocker > > In line 767 of DefaultFileSystemManager.java the UriParser's extractScheme() > method is called: > String scheme = UriParser.extractScheme(buffer.toString()); > This code was added in revision 780730 > http://svn.apache.org/viewvc?view=revision&revision=780730 > It is not clear to me why this change was made. > For the FTP provider, buffer contains a plain file name (i.e. without a path > and definitely not in URI form) > A colon is a valid character for a file name. > However a colon will be interpreted as a URI scheme name. > This causes an exception when the resolved path is checked using > AbstractFileName.checkName() > Sample code: > FileObject fo = > VFS.getManager().resolveFile("ftp://user:pass@host/some/path/some.file"); > fo.getParent().getChildren(); > If /some/path/ contains a child such as PREFIX:SUFFIX then an exception is > thrown: > Exception in thread "main" org.apache.commons.vfs2.FileSystemException: > Invalid descendent file name "PREFIX:SUFFIX". > at > org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveName(DefaultFileSystemManager.java:791) > at > org.apache.commons.vfs2.provider.AbstractFileObject.getChildren(AbstractFileObject.java:710) > at > org.apache.commons.vfs2.provider.ftp.FtpFileObject.getChildren(FtpFileObject.java:420) > Therefore calling code is unable to list the children of the specified folder. -- This message was sent by Atlassian JIRA (v7.6.3#76005)