Issue #15267 has been updated by akr (Akira Tanaka).


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.




----------------------------------------
Bug #15267: File.basename + File.extname does not restore the original name
https://bugs.ruby-lang.org/issues/15267#change-82091

* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Related to #15224, I found the case `File.basename(name, '.*')+File.extname(name) == File.basename(name)` is not true.

```ruby
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)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>