jruby/jruby — pull request #388 by GUI (2012-11-11 23:41:52+00:00)
Title: Fix loading files from paths containing '#' symbols for JRUBY-6339.

As indicated in [JRUBY-6339](http://jira.codehaus.org/browse/JRUBY-6339) JRuby currently breaks when trying to load a JAR file that contains "#" symbols in the filename. This is desired because Tomcat 7's parallel deployment feature requires on that naming convention, but I imagine pound signs might still crop up in other use-cases.

Part of the issue was specific to loading JAR files with "#" symbols in the path, but the other part of the issue I believe is a Ruby regression (tests added for both issues). The regression is seemingly only present when the current working directory contains a "#" in the path and you attempt to load a file from the current directory with the load path set to `.`. The regression is also only present when running JRuby in 1.9 mode.

With the attached code, I was able to successfully deploy a WAR file to tomcat that contained '#' symbols in the path, so I believe this solves the various problems. The basic issue is that Java's `URL` class freaks out when a '#' is unescaped in the path (since it thinks the hash symbol should indicate a fragment). The solution is to use the `URI` class for parsing the paths, and then convert it to a `URL` for reading purposes. This will take care of the necessary escaping and seems to be Java's recommend way of dealing with this (from [URL's docs](http://docs.oracle.com/javase/6/docs/api/java/net/URL.html): "The recommended way to manage the encoding and decoding of URLs is to use URI, and to convert between these two classes using toURI() and URI.toURL()").