Skip to content

Commit

Permalink
Showing 2 changed files with 16 additions and 19 deletions.
31 changes: 16 additions & 15 deletions core/src/main/java/org/jruby/util/JarResource.java
Original file line number Diff line number Diff line change
@@ -19,20 +19,6 @@ public static JarResource create(String pathname) {
Matcher matcher = PREFIX_MATCH.matcher(pathname);
String sanitized = matcher.matches() ? matcher.group(1) : pathname;

try {
// since pathname is actually an uri we need to decode any url decoded characters like %20
// which happens when directory names contain spaces
// but do not to decode '+' to allow '+' inside a filenames
sanitized = sanitized.replace("+", "%2B");
sanitized = URLDecoder.decode(sanitized, "UTF-8");
} catch (IllegalArgumentException iae) {
// something in the path did not decode, so it's probably not a URI
// See jruby/jruby#2264.
return null;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException( "hmm - system does not know UTF-8 string encoding :(" );
}

int bang = sanitized.indexOf('!');
String jarPath = sanitized.substring(0, bang);
String entryPath = sanitized.substring(bang + 1);
@@ -54,7 +40,22 @@ private static JarResource createJarResource(String jarPath, String entryPath, b

if (index == null) {
// Jar doesn't exist
return null;
try {
jarPath = URLDecoder.decode(jarPath, "UTF-8");
entryPath = URLDecoder.decode(entryPath, "UTF-8");
} catch (IllegalArgumentException iae) {
// something in the path did not decode, so it's probably not a URI
// See jruby/jruby#2264.
return null;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException( "hmm - system does not know UTF-8 string encoding :(" );
}
index = jarCache.getIndex(jarPath);

if (index == null) {
// Jar doesn't exist
return null;
}
}

// Try it as directory first, because jars tend to have foo/ entries
4 changes: 0 additions & 4 deletions core/src/test/java/org/jruby/util/JarResourceTest.java
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@ public void testCreateJarResource(){
assertNotNull( resource );
resource = JarResource.create( jar + "!/f o.rb" );
assertNotNull( resource );
resource = JarResource.create( jar + "!/f%20o.rb" );
assertNotNull( resource );
resource = JarResource.create( jar + "!/doesnotexist.rb" );
assertNull( resource );
resource = JarResource.create( jar.replace( ".jar", ".zip" ) + "!/foo.rb" );
@@ -24,8 +22,6 @@ public void testCreateJarResourceWithSpaceCharInPath(){
assertNotNull( resource );
resource = JarResource.create( jar + "!/f o.rb" );
assertNotNull( resource );
resource = JarResource.create( jar + "!/f%20o.rb" );
assertNotNull( resource );
resource = JarResource.create( jar + "!/doesnotexist.rb" );
assertNull( resource );
resource = JarResource.create( jar.replace( ".jar", ".zip" ) + "!/foo.rb" );

0 comments on commit f3d806d

Please sign in to comment.