Backport #3630
closedFile.expand_path doesn't expand content of HOME env. variable
Description
=begin
Dir.chdir 'C:/temp' do
p File.expand_path("a")
ENV["HOME"] = './abc/../xxx'
p File.expand_path("~/a")
ENV["HOME"] = '~/xxx'
p File.expand_path("~/a")
end
Prints:
"C:/temp/a"
"./abc/../xxx/a"
"~/xxx/a"
I'd expect it to print:
"C:/temp/a"
"C:/temp/xxx/a"
"C:/temp/~/xxx/a"
The content of HOME variable should be subject to expansion. If it starts with ~/ the tilde should be treated like a regular directory name to avoid recursion.
=end
Updated by luislavena (Luis Lavena) over 13 years ago
=begin
I have one question for you:
File.expand_path('~') is supposed to expand to HOME. now, if home contains '~', that is supposed to expand to what?
Recursive expansion sounds bad in that context.
=end
Updated by tmat (Tomas Matousek) over 13 years ago
=begin
No it is not suppose to expand tilde again. Only relative paths and .. so that the result of expand_path is a normalized absolute path.
=end
Updated by tmat (Tomas Matousek) over 13 years ago
=begin
That is
Dir.chdir 'c:/temp' do
ENV["HOME"] = '~'
File.expand_path('~').should == 'c:/temp/~'
end
=end
Updated by nobu (Nobuyoshi Nakada) over 13 years ago
- Category set to core
- Status changed from Open to Closed
=begin
Fixed at r28796.
BTW, please avoid filing Bug issues to 1.9.1, unless it is particular to 1.9.1.
In general, 1.9.1 should accept Backport issues only.
=end
Updated by nobu (Nobuyoshi Nakada) over 13 years ago
- Category set to core
- Assignee set to yugui (Yuki Sonoda)
- Priority changed from Normal to 3
=begin
=end
Updated by naruse (Yui NARUSE) about 12 years ago
- Status changed from Assigned to Closed