Skip to content

File.expand_path should fail if ENV['HOME'] isn't an absolute path #1163

@nirvdrum

Description

@nirvdrum

I ran into a corner case with File.expand_path that's causing a test failure with fog. I guess if ENV['HOME'] isn't an absolute path, MRI will fail to expand a path containing '~'.

$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

irb(main):001:0> ENV['HOME'] = '.'
=> "."
irb(main):002:0> File.expand_path('~/.fog')
ArgumentError: non-absolute home
    from (irb):3:in `expand_path'
    from (irb):3
    from /home/nirvdrum/.rbenv/versions/2.0.0-p247/bin/irb:12:in `<main>'
$ ruby --version
jruby 1.7.6 (1.9.3p392) 2013-10-22 6004147 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_45-b18 [linux-amd64]

irb(main):001:0> ENV['HOME'] = '.'
=> "."
irb(main):002:0> File.expand_path('~/.fog')
=> "/home/nirvdrum/dev/workspaces/fog/.fog

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions