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

Gary D. Gregory commented on VFS-793:
-------------------------------------

[~vnashkev] & [~woonsan],

I addressed this in VFS-810. See also the new test 
{{{}org.apache.commons.vfs2.provider.ftp.FtpFileNameParserTestCase{}}}.
May you please verify and close if appropriate?

TY!

> GenericFileName.getURI() returns invalid URI.
> ---------------------------------------------
>
>                 Key: VFS-793
>                 URL: https://issues.apache.org/jira/browse/VFS-793
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.7.0
>            Reporter: Vitali Nashkevich
>            Priority: Minor
>
> The following test case demonstrates the problemĀ 
> {code:java}
> @Test
> public void testGenericFileName() 
>       throws Exception
> {
>       {
>               final String uri = 
> "ftp://blanks:blanks@localhost/path/file_b%20lanks";;
>               final FileName n = 
> FtpFileNameParser.getInstance().parseUri(null, null, uri);
>               assert n instanceof GenericFileName;
>               final String genericUri = n.getURI();
>               assert genericUri.equals(uri.toString());
>       }
>               
>       {
>               final String uri = 
> "ftp://b%20lanks:b%20lanks@localhost/path/file";;
>               final FileName n = 
> FtpFileNameParser.getInstance().parseUri(null, null, uri);
>               assert n instanceof GenericFileName;
>               final String genericUri = n.getURI();
>               assert genericUri.equals(uri.toString());
>       }
> }
> {code}
> The blanks in authority are not properly encoded.
> As a result the following fragment does not work either
> {code:java}
> final URI uri = new URI("ftp://b%20lanks:b%20lanks@localhost:21/path/file";);
> try ( final FileSystemManager m = VFS.getManager() )
> {
>       try ( final FileObject f = m.resolveFile(uri) )
>       {
>               assert f instanceof FtpFileObject;
>               final URI vfsUri = f.getURI();
>               assert uri.equals(vfsUri);
>       }
> }
> {code}
>  
> The call {code:java}f.getURI();{code}
> throws exception
> {noformat}
> java.lang.IllegalArgumentException: Illegal character in authority at index 
> 6: ftp://b lanks:b lanks@localhost/path/file
>       at java.net.URI.create(Unknown Source)
>       at org.apache.commons.vfs2.FileObject.getURI(FileObject.java:303)
>       at GetUriTest.testGetUri_ftp(GetUriTest.java:30)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>       at java.lang.reflect.Method.invoke(Unknown Source)
>       at 
> org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
>       at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
>       at 
> org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
>       at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
>       at 
> org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
>       at 
> org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
>       at 
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
>       at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
>       at java.util.ArrayList.forEach(Unknown Source)
>       at org.testng.TestRunner.privateRun(TestRunner.java:764)
>       at org.testng.TestRunner.run(TestRunner.java:585)
>       at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
>       at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
>       at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
>       at org.testng.SuiteRunner.run(SuiteRunner.java:286)
>       at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
>       at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
>       at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
>       at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
>       at org.testng.TestNG.runSuites(TestNG.java:1069)
>       at org.testng.TestNG.run(TestNG.java:1037)
>       at 
> org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
>       at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
>       at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
> Caused by: java.net.URISyntaxException: Illegal character in authority at 
> index 6: ftp://b lanks:b lanks@localhost/path/file
>       at java.net.URI$Parser.fail(Unknown Source)
>       at java.net.URI$Parser.parseAuthority(Unknown Source)
>       at java.net.URI$Parser.parseHierarchical(Unknown Source)
>       at java.net.URI$Parser.parse(Unknown Source)
>       at java.net.URI.<init>(Unknown Source)
>       ... 31 more
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to