commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Briner" <77c...@gmail.com>
Subject [vfs] vsf2.2.0: non-ascii chars in file name are not handled by createFolder()
Date Thu, 09 Apr 2015 20:05:40 GMT
Geoff,

Nicely put together test case. I was able to reproduce your outcome closely (different FTP
server).

What made it work for me was the following change to the VFS source:

Index: FtpClientFactory.java
===================================================================
--- FtpClientFactory.java	(revision 1535203)
+++ FtpClientFactory.java	(working copy)
@@ -150,7 +150,11 @@
                     {
                         client.setControlEncoding(controlEncoding);
                     }
-
+                    else
+                    {
+                        client.setAutodetectUTF8(true);
+                    }
+                    
                     client.connect(hostname, port);
 
                     final int reply = client.getReplyCode();


… and then not specify any encoding in the test code. I don't know whether this is the right
thing to do in general, but it made all your test cases succeed for me.

Albert


On 16/03/2015 11:07, Geoff Watters wrote:
> All
>
> I am using*commons-vfs2-2.0.jar* and am running into problems when 
> file names contain non-ascii characters. According to 
> https://issues.apache.org/jira/browse/VFS-305 this has been 
> fixed/shipped in 2.0. In my environment I am able to create such file 
> names when using ftp on the command-line (Red Hat Enterprise Linux 
> Server release 5.8 (Tikanga)).
>
> When I execute the following sample code, I get the output shown below.
>
> public class FtpTest {
>     public static void main(String[] args) throws FileSystemException
>     {
>         String host="hhh";
>         String user = "uuu";
>         String password = "ppp";
>         String destDir = "/tmp";
>         FileSystemOptions opts = new FileSystemOptions();
> FtpFileSystemConfigBuilder.getInstance().setControlEncoding(opts, 
> "UTF-8");
>
>         DefaultFileSystemManager manager = new 
> DefaultFileSystemManager();
>         manager.addProvider("ftp", new FtpFileProvider());
>         manager.init();
>
>         String root="ftp://"+user+":"+password+"@"+host+destDir;
>         // Specify a number of directories that should be created 
> under destDir
>         String[] lRoots = new String[4];
>         lRoots[0]= root+"/ftpDebug";
>         lRoots[1]= root+"/ftp\u7684Debug";  // insert a non-ascii char
>         lRoots[2]= root+"/ftp\u7685Debug";  // insert a different 
> non-ascii char
>         lRoots[3]= root+"/ftp\u7684Debug";  // insert the same 
> non-ascii char
>
>         // Verify the ControlEncoding
>         System.out.println("ControlEncoding is 
> "+FtpFileSystemConfigBuilder.getInstance().getControlEncoding(opts));
>
>         int dirCount=0;
>         for (String lRoot: lRoots) {
>             System.out.println(dirCount+") Process directory 
> ["+lRoot+"]");
>             FileObject newDir = manager.resolveFile(lRoot, opts);
>             if (!newDir.exists()) {
>                 try {
>                     System.out.println(dirCount+") "+lRoot+" ::Dir 
> Does Not Exist so Create It ");
>                     newDir.createFolder();
>                     if (newDir.exists())
>                         System.out.println(dirCount+") "+lRoot+" 
> ::Creation Successful ");
>                     else
>                         System.out.println(dirCount+") "+lRoot+" 
> ::Creation Fails ");
>                 }
>                 catch (Exception ex) {
>                     System.out.println(dirCount+") "+lRoot + " raised 
> "+ex);
>                 }
>             }
>             else
>                 System.out.println(dirCount+") "+lRoot+" ::Dir Already 
> Exists ");
>             dirCount++;
>         }
>     }
> }
>
> The output from running the above is:-
>
> ControlEncoding is UTF-8
> 0) Process directory [ftp://uuu:ppp@hhh/tmp/ftpDebug]
> 0) ftp://uuu:ppp@hhh/tmp/ftpDebug ::Dir Does Not Exist so Create It
> 0) ftp://uuu:ppp@hhh/tmp/ftpDebug ::Creation Successful
> 1) Process directory [ftp://uuu:ppp@hhh/tmp/ftpªDebug]
> 1) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Dir Does Not Exist so Create It
> 1) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Creation Successful
> 2) Process directory [ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug]
> 2) ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug ::Dir Does Not Exist so 
> Create It
> 2) ftp://uuu:ppp@hhh/tmp/ftp%Gçš…%@Debug raised 
> org.apache.commons.vfs2.FileSystemException: Could not create 
> folder "ftp://uuu:***@hhh/tmp/ftp%Gçš…%@Debug".
> 3) Process directory [ftp://uuu:ppp@hhh/tmp/ftpªDebug]
> 3) ftp://uuu:ppp@hhh/tmp/ftpªDebug ::Dir Does Not Exist so Create It
> 3) ftp://uuu:ppp@hhh/tmp/ftpªDebug raised 
> org.apache.commons.vfs2.FileSystemException: Could not create folder 
> "ftp://uuu:***@hhh/tmp/ftpªDebug".
>
> After step 1) I see a directory called*/tmp/ftp?Debug*.
> I think this is causing the subsequent creation problem in step 2) and 
> step 3).
> When a directory such as "*ftp\u7684Debug*" does exist, then 
> *exists*() returns the correct result of true, but *createFolder*() 
> creates a directory with name "*ftp?Debug*".
>
> Thanks in advance
> Geoff
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message