Project

General

Profile

Bug #15267

File.basename + File.extname does not restore the original name

Added by nobu (Nobuyoshi Nakada) about 1 year ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:89615]

Description

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.

Files

file-basename-trailing-dot-15267.patch (1.96 KB) file-basename-trailing-dot-15267.patch jeremyevans0 (Jeremy Evans), 08/13/2019 11:48 PM

Related issues

Related to Ruby master - Bug #15244: Method #extname return empty string if filename is dot ('.')FeedbackActions

Associated revisions

Revision e169ad93
Added by nobu (Nobuyoshi Nakada) about 1 month ago

Fixed File.extname at a name ending with a dot

File.extname now returns a dot string at a name ending with a dot.
[Bug #15267]

Revision 4f13927f
Added by nobu (Nobuyoshi Nakada) about 1 month ago

[DOC] no change on Windows [Bug #15267] [ci skip]

History

#1

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

  • Related to Bug #15244: Method #extname return empty string if filename is dot ('.') added

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

Attached is a patch that fixes this issue. With the patch:

name = 'file.'
File.basename(name, '.*')
# => "file."
File.extname(name)
# => ""

Updated by naruse (Yui NARUSE) about 1 month ago

basename(1) seems to result in the base name with the dot, when stripping a wildcard suffix.

basename(1) doesn't handle wildcard.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html

Updated by akr (Akira Tanaka) about 1 month 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.

#6

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Status changed from Open to Closed

Applied in changeset git|e169ad93f44e1944ecf7bb65133fd34e8b868ea8.


Fixed File.extname at a name ending with a dot

File.extname now returns a dot string at a name ending with a dot.
[Bug #15267]

Also available in: Atom PDF