alfianrahmn / xuggle

Automatically exported from code.google.com/p/xuggle
0 stars 0 forks source link

FileProtocolHandler doesn't fully support URLs #216

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Associate FileProtocolHandlerFactory with URLProtocolManager:

URLProtocolManager mgr= URLProtocolManager.getManager();
mgr.registerFactory("javafile", new FileProtocolHandlerFactory());

2. Create a javafile url that has spaces in it using the java URI API and give 
it to an ISimpleMediaFile:

    File file= new File("/some path/some file.txt");
    URI uri1= file.toURI();
    URI uri2= new URI("javafile", uri1.getSchemeSpecificPart(), uri1.getFragment());

    ISimpleMediaFile info= new SimpleMediaFile();
    info.setURL(uri2);     // javafile:///some%20path/some%20file.txt

3. Use the ISimpleMediaFile above to do a conversion.  FileProtocolHandler 
won't be able to open the file and you'll see 
this logged (note how the spaces have not be unescaped):

    url->filename: javafile:///some%20path/some%20file.txt->/some%20path/some%20file.txt

4. This is because in FileProtocolHandler#getFilename, the url->file conversion 
is only done by chopping off the 
protocol prefix ("javafile://") and does no escaped char processing.

What is the expected output? What do you see instead?

FileProtocolHandler should properly decode URLs, particularly escaped 
characters like spaces.

Original issue reported on code.google.com by paleozogt on 6 Oct 2009 at 6:00

GoogleCodeExporter commented 8 years ago
FileProtocolHandler#getFilename should be implemented (more or less) like this 
in order to properly 
support url encoding:

    private String getFilename(String url)
    {
      try {
          File file= new File(new URI(url));
          return file.getAbsolutePath();
      } catch (URISyntaxException exp) {
          return null;
      }
    }  

Original comment by paleozogt on 6 Oct 2009 at 6:02