Project

General

Profile

Bug #15324

Dir.home test doesn't match actual Ruby or system behaviour

Added by chrisseaton (Chris Seaton) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:89911]

Description

This test currently asserts that Dir.home(user) should return ENV['HOME'] if user is the current user.

We don't think this is correct - Dir.home(user) uses the expanded value of ~user, which explictly uses the login database, and explicitly not any current value of HOME.

See the documentation on tilde expansion here:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01

"[if there is an explict user name after the tilde then] the tilde-prefix shall be replaced by a pathname of the initial working directory associated with the login name obtained using the getpwnam() function as defined in the System Interfaces volume of POSIX.1-2017 [as opposed to reading HOME]"

getpwnam is what File.expand_path does.

To see the problem, run MRI's test with HOME set to something else (again, see the link above to see that setting HOME is explicitly allowed).

$ HOME=/nothing make test-all
...
  1) Failure:
TestDir#test_home [/Users/chrisseaton/Documents/mri-test-upstream/ruby/test/ruby/test_dir.rb:378]:
<"/nothing"> expected but was
<"/Users/chrisseaton">.
...

We've encountered this test failure for real, so it isn't hypothetical.

The patch corrects the test to match actual Ruby behaviour.


Files

dir.patch (538 Bytes) dir.patch chrisseaton (Chris Seaton), 11/20/2018 04:09 PM

Also available in: Atom PDF