Skip to content

Commit

Permalink
Merge pull request #7738 from headius/dir_home_nil_user
Browse files Browse the repository at this point in the history
Fix Dir.home called with nil user
  • Loading branch information
headius committed Mar 29, 2023
2 parents 95c5be4 + 30c48ac commit fcce721
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyDir.java
Expand Up @@ -632,6 +632,10 @@ public static IRubyObject home(ThreadContext context, IRubyObject recv) {

@JRubyMethod(name = "home", meta = true)
public static IRubyObject home(ThreadContext context, IRubyObject recv, IRubyObject user) {
if (user == null || user.isNil()) {
return getHomeDirectoryPath(context);
}

RubyString userString = user.convertToString();

userString.verifyAsciiCompatible();
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/dir/home_spec.rb
Expand Up @@ -85,4 +85,10 @@
it "raises an ArgumentError if the named user doesn't exist" do
-> { Dir.home('geuw2n288dh2k') }.should raise_error(ArgumentError)
end

describe "when called with a nil user name" do
it "returns the current user's home directory, reading $HOME first" do
Dir.home(nil).should == "/rubyspec_home"
end
end
end

0 comments on commit fcce721

Please sign in to comment.