Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Expand "~" from File.absolute_path properly. #1878

Merged
3 commits merged into from

2 participants

@ghost

Fixes #1877.

@travisbot

This pull request passes (merged 59b878bb into 2d12be2).

@ghost ghost merged commit c32cafe into from
@travisbot

This pull request fails (merged 615a025 into 2d12be2).

@travisbot

This pull request fails (merged 491ab892 into 2d12be2).

@travisbot

This pull request passes (merged 88d00caf into 2d12be2).

@travisbot

This pull request fails (merged 6ecc67a into 2d12be2).

This issue was closed.
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.
View
5 kernel/common/file19.rb
@@ -50,8 +50,9 @@ def size
end
def self.absolute_path(obj, dir = nil)
- if dir.nil?
- path(obj)
+ obj = path(obj)
+ if obj[0] == "~"
+ File.join Dir.getwd, dir.to_s, obj
else
expand_path(obj, dir)
end
View
14 spec/ruby/core/file/absolute_path_spec.rb
@@ -11,15 +11,23 @@
end
it "resolves paths relative to the current working directory" do
- Dir.chdir(File.dirname(@abs)) do |dir|
- File.absolute_path(File.expand_path('./' + File.basename(__FILE__))).should == @abs
+ path = File.dirname(@abs)
+ Dir.chdir(path) do
+ File.absolute_path('hello.txt').should == File.join(path, 'hello.txt')
end
end
- it "doesn't expand '~'" do
+ it "does not expand '~' to a home directory." do
File.absolute_path('~').should_not == File.expand_path('~')
end
+ it "does not expand '~user' to a home directory." do
+ path = File.dirname(@abs)
+ Dir.chdir(path) do
+ File.absolute_path('~user').should == File.join(path, '~user')
+ end
+ end
+
it "accepts a second argument of a directory from which to resolve the path" do
File.absolute_path(__FILE__, File.dirname(__FILE__)).should == @abs
end
Something went wrong with that request. Please try again.