Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ensure relative paths do NOT load unless "." is on $LOAD_PATH
there is an extra search on "." necessary otherwise the relative path
will be found via the classloader. the regular mri spec does not fail
since current directory in java is independent from the current directory
in ruby
  • Loading branch information
mkristian committed Feb 19, 2015
1 parent 38f3892 commit 1b65f62
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
Expand Up @@ -148,9 +148,15 @@ private FoundLibrary findResourceLibrary(String baseName, String suffix) {
// if (library != null) return library;
// }

// ruby does not load a relative path unless the current working directory is in $LOAD_PATH
FoundLibrary library = findFileResourceWithLoadPath(baseName, suffix, ".");
// we did not find the file on the $LOAD_PATH but in current directory so we need to treat it
// as not found (the classloader search below will find it otherwise)
if (library != null) return null;

// load the jruby kernel and all resource added to $CLASSPATH
if (!runtime.getInstanceConfig().isLegacyLoadServiceEnabled()) {
FoundLibrary library = findFileResourceWithLoadPath(baseName, suffix, URLResource.URI_CLASSLOADER);
library = findFileResourceWithLoadPath(baseName, suffix, URLResource.URI_CLASSLOADER);
if (library != null) return library;
}

Expand Down
1 change: 1 addition & 0 deletions rakelib/test.rake
Expand Up @@ -101,6 +101,7 @@ namespace :test do
end
t.test_files = files
t.verbose = true
t.ruby_opts << '-I.'
t.ruby_opts << '-J-ea'
t.ruby_opts << '-J-cp test:test/target/test-classes:core/target/test-classes'
end
Expand Down
14 changes: 2 additions & 12 deletions test/jruby/test_dir_with_plusses.rb
@@ -1,22 +1,12 @@
require 'test/unit'
require 'test/jruby/test_helper'

class TestDirWithPlusses < Test::Unit::TestCase
include TestHelper

def prefix
if JRuby.runtime.instance_config.legacy_load_service_enabled? || IS_JAR_EXECUTION
File.dirname(File.expand_path(__FILE__))
else
'uri:classloader:/test/jruby'
end
end

def test_loaded_FILE_in_dir_with_plusses
begin
load 'test/jruby/dir_with_plusses_+++/required.rb'
assert_equal(
File.join(prefix, 'dir_with_plusses_+++', 'required.rb'),
File.join(File.dirname(File.expand_path(__FILE__)), 'dir_with_plusses_+++', 'required.rb'),
$dir_with_plusses_FILE
)
ensure
Expand All @@ -29,7 +19,7 @@ def test_required_FILE_in_dir_with_plusses
begin
require 'test/jruby/dir_with_plusses_+++/required.rb'
assert_equal(
File.join(prefix, 'dir_with_plusses_+++', 'required.rb'),
File.join(File.dirname(File.expand_path(__FILE__)), 'dir_with_plusses_+++', 'required.rb'),
$dir_with_plusses_FILE
)
ensure
Expand Down
2 changes: 1 addition & 1 deletion test/jruby/test_jarred_gems_with_spaces_in_directory.rb
Expand Up @@ -5,7 +5,7 @@ class TestJarredGemsWithSpacesInDirectory < Test::Unit::TestCase
include TestHelper

def test_list_gem_from_jar_with_spaces_in_directory
out = jruby(%q{-r"test/jruby/dir with spaces/testgem.jar" -S jgem list})
out = jruby(%q{-r"./test/jruby/dir with spaces/testgem.jar" -S jgem list})
assert(out =~ /testgem/)

cp = ENV['CLASSPATH']
Expand Down
10 changes: 1 addition & 9 deletions test/jruby/test_load.rb
Expand Up @@ -198,15 +198,7 @@ def require(file)

res = File.expand_path($loading_behavior_result)

assert_equal File.join(prefix, 'test_loading_behavior.rb'), res
end

def prefix
if JRuby.runtime.instance_config.legacy_load_service_enabled? || IS_JAR_EXECUTION
File.expand_path('test/jruby')
else
'uri:classloader:/test/jruby'
end
assert_equal File.join(File.expand_path('test/jruby'), 'test_loading_behavior.rb'), res
end

# JRUBY-3894
Expand Down

0 comments on commit 1b65f62

Please sign in to comment.