Project

General

Profile

Backport #3630

File.expand_path doesn't expand content of HOME env. variable

Added by tmat (Tomas Matousek) about 9 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:31537]

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

History

#1

Updated by luislavena (Luis Lavena) about 9 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

#2

Updated by tmat (Tomas Matousek) about 9 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

#3

Updated by tmat (Tomas Matousek) about 9 years ago

=begin
That is

Dir.chdir 'c:/temp' do
ENV["HOME"] = '~'
File.expand_path('~').should == 'c:/temp/~'
end
=end

#4

Updated by nobu (Nobuyoshi Nakada) about 9 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

#5

Updated by nobu (Nobuyoshi Nakada) about 9 years ago

  • Category set to core
  • Assignee set to yugui (Yuki Sonoda)
  • Priority changed from Normal to 3

=begin

=end

#6

Updated by mame (Yusuke Endoh) about 9 years ago

  • Status changed from Closed to Assigned

=begin

=end

Updated by naruse (Yui NARUSE) over 7 years ago

  • Status changed from Assigned to Closed

Also available in: Atom PDF