Skip to content

Commit 96000f6

Browse files
committed
Pathname#initialize should raise TypeError if coercion fails
* Found by ruby/spec, and confirmed pathname.c did the same.
1 parent 438fad2 commit 96000f6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/pathname.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ class Pathname
238238
# If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised.
239239
#
240240
def initialize(path)
241-
path = path.to_path if path.respond_to? :to_path
241+
unless String === path
242+
path = path.to_path if path.respond_to? :to_path
243+
raise TypeError unless String === path
244+
end
245+
242246
if path.include?("\0")
243247
raise ArgumentError, "pathname contains \\0: #{path.inspect}"
244248
end

0 commit comments

Comments
 (0)