Project

General

Profile

Actions

Backport #3630

closed

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

Added by tmat (Tomas Matousek) over 13 years ago. Updated about 12 years ago.

Status:
Closed
[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

Actions #1

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

Actions #2

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

Actions #3

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

Actions #4

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

Actions #5

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

Actions #6

Updated by mame (Yusuke Endoh) over 13 years ago

  • Status changed from Closed to Assigned

=begin

=end

Updated by naruse (Yui NARUSE) about 12 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0