Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix File.realpath (for #2165) #2210

Merged
merged 2 commits into from

2 participants

@kachick
Collaborator

Fixes #2165

@brixen brixen merged commit 20ddc63 into rubinius:master
@kachick
Collaborator

Thanks!

@kachick kachick deleted the kachick:fix-file-realpath_should_raise_error_if_invalid_path branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +4 −0 kernel/common/file19.rb
  2. +14 −1 spec/ruby/core/file/realpath_spec.rb
View
4 kernel/common/file19.rb
@@ -124,6 +124,10 @@ def self.realpath(path, basedir = nil)
end
end
+ unless exists? real
+ raise Errno::ENOENT, real
+ end
+
real
end
end
View
15 spec/ruby/core/file/realpath_spec.rb
@@ -14,10 +14,15 @@
touch @file
File.symlink(@file, @link)
+
+ @fake_file = File.join(@real_dir, 'fake_file')
+ @fake_link = File.join(@link_dir, 'fake_link')
+
+ File.symlink(@fake_file, @fake_link)
end
after :each do
- rm_r @file, @link, @real_dir, @link_dir
+ rm_r @file, @link, @fake_link, @real_dir, @link_dir
end
it "returns '/' when passed '/'" do
@@ -43,5 +48,13 @@
File.symlink(@link, @link)
lambda { File.realpath(@link) }.should raise_error(Errno::ELOOP)
end
+
+ it "raises Errno::ENOENT if file is absent" do
+ lambda { File.realpath(@fake_file) }.should raise_error(Errno::ENOENT)
+ end
+
+ it "raises Errno::ENOENT if symlink points an absent file" do
+ lambda { File.realpath(@fake_link) }.should raise_error(Errno::ENOENT)
+ end
end
end
Something went wrong with that request. Please try again.