Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ class Pathname
def initialize(path)
unless String === path
path = path.to_path if path.respond_to? :to_path
raise TypeError unless String === path
path = path.to_str if path.respond_to? :to_str
raise TypeError, "Pathname.new requires a String, #to_path or #to_str" unless String === path
end

if path.include?("\0")
Expand Down
4 changes: 4 additions & 0 deletions test/pathname/test_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ def test_initialize
assert_equal('a', p1.to_s)
p2 = Pathname.new(p1)
assert_equal(p1, p2)

obj = Object.new
def obj.to_str; "a/b"; end
assert_equal("a/b", Pathname.new(obj).to_s)
end

def test_initialize_nul
Expand Down