Skip to content

Commit

Permalink
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/util/JarResource.java
Original file line number Diff line number Diff line change
@@ -25,12 +25,6 @@ public static JarResource create(String pathname) {
// normalize path -- issue #2017
if (entryPath.startsWith("//")) entryPath = entryPath.substring(1);

// Resources will not find paths which end with "/" as a valid directory entry. We sanitize here before
// we create the resources since jar resources cache and we are normalizing the path.
if (entryPath.length() > 1 && entryPath.endsWith("/")) {
entryPath = entryPath.substring(0, entryPath.length() - 1);
}

// TODO: Do we really need to support both test.jar!foo/bar.rb and test.jar!/foo/bar.rb cases?
JarResource resource = createJarResource(jarPath, entryPath, false);

@@ -69,6 +63,12 @@ private static JarResource createJarResource(String jarPath, String entryPath, b
String[] entries = index.getDirEntries(entryPath);
if (entries != null) {
return new JarDirectoryResource(jarPath, rootSlashPrefix, entryPath, entries);
} else if (entryPath.length() > 1 && entryPath.endsWith("/")) { // in case 'foo/' passed
entries = index.getDirEntries(entryPath.substring(0, entryPath.length() - 1));

if (entries != null) {
return new JarDirectoryResource(jarPath, rootSlashPrefix, entryPath, entries);
}
}

JarEntry jarEntry = index.getJarEntry(entryPath);
8 changes: 7 additions & 1 deletion test/jruby/test_dir.rb
Original file line number Diff line number Diff line change
@@ -248,12 +248,18 @@ def test_stat_directory_in_jar_with_trailing_slash
$CLASSPATH << jar_file
source_file = "jar:file:#{jar_file}!/test/require_relative1.rb"
assert File.exist?(source_file), "test is wrong, #{source_file} doesn't even exist"
assert_equal false, File.directory?(source_file)
assert_equal false, File.directory?(source_file + "/")
assert_raise(Errno::ENOENT) do
File.stat(source_file + "/")
end
source_dir = File.dirname(source_file)
assert File.directory?(source_dir), "#{source_dir} not found"
source_dir += "/"
assert File.directory?(source_dir), "#{source_dir} claims to not be a directory"
assert_equal true, File.stat(source_dir).directory?
end

# JRUBY-4983
def test_entries_unicode
utf8_dir = "testDir_1/glk\u00a9"

0 comments on commit 946befd

Please sign in to comment.