Skip to content

Error when expanding path with ~ and no HOME #5661

@headius

Description

@headius

When expanding a path starting with a tilde, like ~/foo, if the HOME environment variable has been removed from ENV we raise an error. MRI does not, and must be using some fallback logic to expand HOME properly when it has been cleared (or else capturing it at startup?).

[] ~/projects/jruby $ rvm ruby-2.5.3 do ruby -e 'ENV.delete("HOME"); p ENV["HOME"]; p File.expand_path "~/foo.rb"'
nil
"/Users/headius/foo.rb"

[] ~/projects/jruby $ ruby -e 'ENV.delete("HOME"); p ENV["HOME"]; p File.expand_path "~/foo.rb"'
nil
ArgumentError: couldn't find HOME environment -- expanding `~'
  expand_path at org/jruby/RubyFile.java:844
       <main> at -e:1

This manifests on current master and has probably been this way for a long time.

Note that we have logic for expanding the home path in various places that should be checked for this behavior:

  • RubyFile.expand_path and similar that eventually attempt to expand a tilde to a HOME path.
  • RubyDir.getHomeDirectoryPath used by some of the above, which has several fallbacks to try to find a HOME but seems to not have quite enough?
  • Load logic within LoadService and LibrarySearcher. I'm currently working on a refactor of these, so the code is in flux. The logic I am now calling lives near the logic in RubyDir but simple returns null if the HOME environment variable cannot be resolved, with no fallbacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions