[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: JBoss with spaces in the directory name

alesj do-not-reply at jboss.com
Thu Jul 24 07:14:17 EDT 2008


"adrian at jboss.org" wrote : 
  | I'd guess the fix invloves adding a
  | URLDecoder.decode(uri, "UTF-8");
  | to FileSystemContext.getFile(URI)
  | but there might be other places that need this fix?
Shouldn't the URI and File take care of those %20 'chars'?

I'm trying to put together a test that would fail,
but so far no luck. :-)

I've added this

  |    public void testPathWithSpaces() throws Throwable
  |    {
  |       String path = "/test/pckg with spaces/somefile.txt";
  |       VirtualFile vf = testPath(path);
  |       assertNotNull(vf);
  |       URI uri = getResource("/vfs").toURI();
  |       String uriPath = uri.getPath();
  |       URI fileURI = vf.toURI();
  |       String fileURIPath = fileURI.getPath();
  |       assertEquals(uriPath + path, fileURIPath);
  |    }
  | 
but all is ok. :-)

Since your case fails when looking up child,
perhaps a proper fix would be to fix the path 
in VirtualFile::getChild.


  |    public static String fixName(String name)
  |    {
  |       if (name == null)
  |          throw new IllegalArgumentException("Null name");
  | 
  |       int length = name.length();
  |       if (length <= 1)
  |          return name;
  |       if (name.charAt(length-1) == '/')
  |          return name.substring(0, length-1);
  | 
  |       return decode(name);
  |    }
  | 
  |    /**
  |     * Decode the path with UTF-8 encoding..
  |     *
  |     * @param path the path to decode
  |     * @return decoded path
  |     */
  |    public static String decode(String path)
  |    {
  |       return decode(path, DEFAULT_ENCODING);
  |    }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4166377#4166377

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4166377



More information about the jboss-dev-forums mailing list