Skip to content

Commit f3d806d

Browse files
committed
improve the case when the path for a jar-file needs to be URL-decoded
it removes the case my.jar!/f%20o.rb which matches the behaviour of file:f%20o.rb Sponsored by Lookout Inc.
1 parent d220103 commit f3d806d

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

core/src/main/java/org/jruby/util/JarResource.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ public static JarResource create(String pathname) {
1919
Matcher matcher = PREFIX_MATCH.matcher(pathname);
2020
String sanitized = matcher.matches() ? matcher.group(1) : pathname;
2121

22-
try {
23-
// since pathname is actually an uri we need to decode any url decoded characters like %20
24-
// which happens when directory names contain spaces
25-
// but do not to decode '+' to allow '+' inside a filenames
26-
sanitized = sanitized.replace("+", "%2B");
27-
sanitized = URLDecoder.decode(sanitized, "UTF-8");
28-
} catch (IllegalArgumentException iae) {
29-
// something in the path did not decode, so it's probably not a URI
30-
// See jruby/jruby#2264.
31-
return null;
32-
} catch (UnsupportedEncodingException e) {
33-
throw new RuntimeException( "hmm - system does not know UTF-8 string encoding :(" );
34-
}
35-
3622
int bang = sanitized.indexOf('!');
3723
String jarPath = sanitized.substring(0, bang);
3824
String entryPath = sanitized.substring(bang + 1);
@@ -54,7 +40,22 @@ private static JarResource createJarResource(String jarPath, String entryPath, b
5440

5541
if (index == null) {
5642
// Jar doesn't exist
57-
return null;
43+
try {
44+
jarPath = URLDecoder.decode(jarPath, "UTF-8");
45+
entryPath = URLDecoder.decode(entryPath, "UTF-8");
46+
} catch (IllegalArgumentException iae) {
47+
// something in the path did not decode, so it's probably not a URI
48+
// See jruby/jruby#2264.
49+
return null;
50+
} catch (UnsupportedEncodingException e) {
51+
throw new RuntimeException( "hmm - system does not know UTF-8 string encoding :(" );
52+
}
53+
index = jarCache.getIndex(jarPath);
54+
55+
if (index == null) {
56+
// Jar doesn't exist
57+
return null;
58+
}
5859
}
5960

6061
// Try it as directory first, because jars tend to have foo/ entries

core/src/test/java/org/jruby/util/JarResourceTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public void testCreateJarResource(){
1010
assertNotNull( resource );
1111
resource = JarResource.create( jar + "!/f o.rb" );
1212
assertNotNull( resource );
13-
resource = JarResource.create( jar + "!/f%20o.rb" );
14-
assertNotNull( resource );
1513
resource = JarResource.create( jar + "!/doesnotexist.rb" );
1614
assertNull( resource );
1715
resource = JarResource.create( jar.replace( ".jar", ".zip" ) + "!/foo.rb" );
@@ -24,8 +22,6 @@ public void testCreateJarResourceWithSpaceCharInPath(){
2422
assertNotNull( resource );
2523
resource = JarResource.create( jar + "!/f o.rb" );
2624
assertNotNull( resource );
27-
resource = JarResource.create( jar + "!/f%20o.rb" );
28-
assertNotNull( resource );
2925
resource = JarResource.create( jar + "!/doesnotexist.rb" );
3026
assertNull( resource );
3127
resource = JarResource.create( jar.replace( ".jar", ".zip" ) + "!/foo.rb" );

0 commit comments

Comments
 (0)