commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Otto Fowler (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (VFS-398) FtpFileObject.getChildren() fails when a folder contains a file with a colon in the name
Date Fri, 16 Feb 2018 04:34:00 GMT

    [ https://issues.apache.org/jira/browse/VFS-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16366599#comment-16366599
] 

Otto Fowler commented on VFS-398:
---------------------------------

OK.

After further reflection and review, here it is:

The code wants to support a string the may be a url or may not be at the same time.

The issue is, that no matter what we do we can never know if the ':' is the scheme marker
or part of the file name.

each scheme by definition supports a different scheme part ( the part after the : ) and some
don't even have one.

Add to this, that the scheme is used in the system to map to a provider, and those can be
registered with whatever scheme a developer wants.

 

My proposal is to limit the recognized scheme's returned by extractScheme to those registered
in the system.  I believe this is the most correct way to do this.
 * it is only way to be sure that it is a scheme and not just a ':'
 * the system can only support registered schemes anyway

 

I all system tests passing ( along with new tests for this issue ) with the following replacement
method being used in place of extractScheme

 
{code:java}
public static String extractSupportedScheme(final Set<String> supportedScheme, final
String uri) {
    return extractSupportedScheme(supportedScheme, uri, null);
}

public static String extractSupportedScheme(final Set<String> supportedScheme, final
String uri, StringBuilder buffer) {
    if (buffer != null) {
        buffer.setLength(0);
        buffer.append(uri);
    }

    for(String schema : supportedScheme) {
        if(uri.startsWith(schema + ":")) {
            if (buffer != null) {
                buffer.delete(0, uri.indexOf(':') + 1);
            }
            return schema;
        }
    }
    return null;
}
{code}
Thoughts?  Improvements?

 

 

> 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)

Mime
View raw message