You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Tim Lebedkov (JIRA)" <ji...@apache.org> on 2008/03/26 15:45:24 UTC

[jira] Created: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

FileObject..getName().getURI() returns URIs with spaces
-------------------------------------------------------

                 Key: VFS-203
                 URL: https://issues.apache.org/jira/browse/VFS-203
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 1.0
            Reporter: Tim Lebedkov


Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "Mario Ivankovits (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675791#action_12675791 ] 

Mario Ivankovits commented on VFS-203:
--------------------------------------

Hmmm .... normally escaping these special charachters should do the trick, e.g. %20 instead of space.

It might not look nice, but this is how URIs work (IMHO)

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "Sergey Vladimirov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Vladimirov updated VFS-203:
----------------------------------

    Attachment: patch.txt

Okay, proposed patch in attachment. It overrides createURI() method in LocalFileName (since only this class allows spaces in names) and replaces getPath() call with new URI(null, null, getPath(), null).toString().

Simple test case (included) shows that result URI parsed by java.net.URI. And, as well, it can be passed back to VFS....resolveFile() - and it will work.

The problems is broken UrlProviderTestCase :(
don't know why yet

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>         Attachments: patch.txt
>
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675797#action_12675797 ] 

Joerg Schaible commented on VFS-203:
------------------------------------

Benjamin Bentman once gave a good summary of this issue on the Maven list. Citation of  http://markmail.org/message/lbnhjsmzrc2ht2fa and following below:

{quote}
URLs and filesystem paths are really two different beasts and converting between them is not trivial. The main source of problems is that different encoding rules apply for the strings that make up a URL or filesystem path. 
For example, consider the following code snippet: 
 File file = new File( "foo bar+foo" );
 URL url = file.toURI().toURL();
 System.out.println( file.toURL() );
 System.out.println( url );
 System.out.println( url.getPath() );
 System.out.println( URLDecoder.decode( url.getPath(), "UTF-8" ) );

which outputs something like 
 file:/M:/scratch-pad/foo bar+foo
 file:/M:/scratch-pad/foo%20bar+foo
 /M:/scratch-pad/foo%20bar+foo
 /M:/scratch-pad/foo bar foo

First of all, please note that File.toURL() does not escape the space character. This yields an invalid URL, as per RFC 2396, section 2.4.3 "Excluded US-ASCII Characters". The class java.net.URL will silently accept such invalid URLs, in contrast java.net.URI will not (see also URL.toURI()). For this reason, this API method has already been deprecated and should be replaced with File.toURI().toURL(). 
Next, URL.getPath() does in general not return a string that can be used as a filesystem path. It returns a substring of the URL and as such can contain escape sequences. The prominent example is the space character which will show up as "%20". People sometimes hack around this by means of replace("%20", " ") but that does simply not cover all cases. It's worth to mention that on the other hand the related method URI.getPath() does decode escapes but still the result is not a filesystem path (compare the source for the constructor File(URI)). 
To decode a URL, people sometimes also choose java.net.URLDecoder. The pitfall with this class is that is actually performs HTML form decoding which is yet another encoding and not the same as the URL encoding (compare last paragraph in class javadoc about java.net.URL). For instance, a URLDecoder will errorneously convert the character "+" into a space as illustrated by the last sysout in the example above. 
Code targetting JRE 1.4+ should easily avoid these problems by using 
 new File( new URI( url.toString() ) )

when converting a URL to a filesystem path and with JDKs >= 1.5 using 
 file.toURI().toURL()

when converting back. 
JRE 1.4 is happily returning invalid/unescaped URLs from ClassLoader.getResource(), making the above suggestion fail with a URISyntaxException. 
The suggestion is to use FileUtils.toFile(URL) from Commons IO.
{quote}

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "PalinF (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12833842#action_12833842 ] 

PalinF commented on VFS-203:
----------------------------

Is there any activity on this project and in for this bug in particular ?

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>         Attachments: patch.txt
>
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "Sergey Vladimirov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675153#action_12675153 ] 

Sergey Vladimirov commented on VFS-203:
---------------------------------------

+1 for this bug. It affects FileName -> URI conversion as in this scenario:


FileObject fo = VFS.getManager().resolveFile("tmp://some file.txt");
new URI(fo.getName.toURI())
 - throws URISyntaxException because of illegal char " "


Let me know if you want patch for it. Kinda tired of sending patches without any response.
(And as a novice i can't even ask for committer access... sigh... )

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "Ralph Goers (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675796#action_12675796 ] 

Ralph Goers commented on VFS-203:
---------------------------------

Yes, the URI should contain %20 but the actual file would hopefully contain a space. In any case, I'd still like to see the patch.

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "Ralph Goers (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675776#action_12675776 ] 

Ralph Goers commented on VFS-203:
---------------------------------

Yes, please send a patch. I'm fairly new to VFS and am just starting to go through Jira. I could use the help!

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (VFS-203) FileObject..getName().getURI() returns URIs with spaces

Posted by "PalinF (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/VFS-203?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

PalinF updated VFS-203:
-----------------------

    Comment: was deleted

(was: Is there any activity on this project and in for this bug in particular ?)

> FileObject..getName().getURI() returns URIs with spaces
> -------------------------------------------------------
>
>                 Key: VFS-203
>                 URL: https://issues.apache.org/jira/browse/VFS-203
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>            Reporter: Tim Lebedkov
>         Attachments: patch.txt
>
>
> Windows supports file names with spaces and '#'. AFAIK spaces are not allowed in URIs and # will be interpreted as an URI fragment.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.