Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0b589e0a4ce0
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5a08be66469a
Choose a head ref
  • 4 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 22, 2015

  1. fix creating FileResource with CWD a uri-like path and path a regular…

    … file
    
    if the path is an absolute path to regular file and the CWD is using a
    uri:classloader:/ then the absolute path on the filesystem "wins"
    
    fixes #3071
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 22, 2015
    Copy the full SHA
    edac27b View commit details
  2. Copy the full SHA
    0cce926 View commit details
  3. Merge branch 'jruby-1_7'

    Conflicts:
    	core/src/main/java/org/jruby/util/JRubyFile.java
    	lib/pom.rb
    	test/test_file.rb
    mkristian committed Jun 22, 2015
    Copy the full SHA
    1f9aac5 View commit details

Commits on Jun 23, 2015

  1. Copy the full SHA
    5a08be6 View commit details
Showing with 30 additions and 7 deletions.
  1. +8 −6 core/src/main/java/org/jruby/util/JRubyFile.java
  2. +1 −1 lib/pom.rb
  3. +21 −0 test/jruby/test_file.rb
14 changes: 8 additions & 6 deletions core/src/main/java/org/jruby/util/JRubyFile.java
Original file line number Diff line number Diff line change
@@ -108,7 +108,8 @@ private static FileResource createResource(Ruby runtime, String cwd, String path
}
}

if (cwd != null && (cwd.startsWith("uri:") || cwd.startsWith("file:"))) {
File internal = new JavaSecuredFile(pathname);
if (cwd != null && !internal.isAbsolute() && (cwd.startsWith("uri:") || cwd.startsWith("file:"))) {
return createResource(runtime, null, cwd + "/" + pathname);
}

@@ -133,14 +134,15 @@ private static JRubyFile createNoUnicodeConversion(String cwd, String pathname)
pathname = pathname.substring(5);
}
File internal = new JavaSecuredFile(pathname);
if(cwd != null && cwd.startsWith("uri:") && !pathname.startsWith("uri:") && !pathname.contains("!/") && !internal.isAbsolute()) {
if (internal.isAbsolute()) {
return new JRubyFile(internal);
}
if(cwd != null && cwd.startsWith("uri:") && !pathname.startsWith("uri:") && !pathname.contains("!/")) {
return new JRubyFile(cwd + "/" + pathname);
}
internal = new JavaSecuredFile(cwd, pathname);
if(!internal.isAbsolute()) {
internal = new JavaSecuredFile(cwd, pathname);
if(!internal.isAbsolute()) {
throw new IllegalArgumentException("Neither current working directory ("+cwd+") nor pathname ("+pathname+") led to an absolute path");
}
throw new IllegalArgumentException("Neither current working directory ("+cwd+") nor pathname ("+pathname+") led to an absolute path");
}
return new JRubyFile(internal);
}
2 changes: 1 addition & 1 deletion lib/pom.rb
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ def version
ImportedGem.new( 'power_assert', 'power_assert.version', true ),
ImportedGem.new( 'psych', '2.0.14.pre1', true ),
ImportedGem.new( 'json', 'json.version', true ),
ImportedGem.new( 'jar-dependencies', '0.1.14', true )
ImportedGem.new( 'jar-dependencies', '0.1.15', true )
]

project 'JRuby Lib Setup' do
21 changes: 21 additions & 0 deletions test/jruby/test_file.rb
Original file line number Diff line number Diff line change
@@ -964,6 +964,27 @@ def test_file_utf8
end
end

# GH-3074
def test_file_with_absolute_path_and_uri_path_as_cwd
filename = File.expand_path( 'test_absolute_path_and_uri_path_as_cwd' )

Dir.chdir('uri:classloader:/') do
begin
f = File.new(filename, File::CREAT)
assert_equal(nil, f.read(1))

assert File.file?(filename)
assert File.exist?(filename)
ensure
f.close
File.delete(filename)

assert !File.file?(filename)
assert !File.exist?(filename)
end
end
end

def test_file_create
filename = '2nnever'
f = File.new(filename, File::CREAT)