Skip to content

Commit f8e0cae

Browse files
committed
Handle Windows NTFS edge case in Pathname#sub_ext
1 parent 177a86d commit f8e0cae

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/pathname.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ def sub(pattern, *rest, &block)
308308
# #=> #<Pathname:/usr/bin/shutdown.rb>
309309
def sub_ext(repl)
310310
ext = File.extname(@path)
311+
312+
# File.extname("foo.bar:stream") returns ".bar" on NTFS and not ".bar:stream"
313+
# (see ruby_enc_find_extname()).
314+
# The behavior of Pathname#sub_ext is to replace everything
315+
# from the start of the extname until the end of the path with repl.
316+
unless @path.end_with?(ext)
317+
ext = @path[@path.rindex(ext)..]
318+
end
319+
311320
self.class.new(@path.chomp(ext) + repl)
312321
end
313322

0 commit comments

Comments
 (0)