File.basename + File.extname does not restore the original name
Related to #15224, I found the case
File.basename(name, '.*')+File.extname(name) == File.basename(name) is not true.
name = 'file.' File.basename(name, '.*') #=> "name" File.extname(name) #=> ""
Both do not contain the last dot.
basename(1) seems to result in the base name with the dot, when stripping a wildcard suffix.
$ basename name. '.*' name.
Updated by jeremyevans0 (Jeremy Evans) about 2 years ago
Attached is a patch that fixes this issue. With the patch:
name = 'file.' File.basename(name, '.*') # => "file." File.extname(name) # => ""
Updated by akr (Akira Tanaka) about 2 years ago
I think we should change File.extname instead of File.basename, as:
File.basename("name.", ".*") #=> "name" File.extname("name.") #=> "."
We can explain File.extname as:
File.extname(x) returns what File.basename(x, ".*") removes.
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
- Status changed from Open to Closed