[ruby-core:94332] [Ruby master Bug#15244] Method #extname return empty string if filename is dot ('.')
From:
merch-redmine@...
Date:
2019-08-14 01:15:26 UTC
List:
ruby-core #94332
Issue #15244 has been updated by jeremyevans0 (Jeremy Evans).
File multiple-leading-dot-basename-extname-15244.patch added
I agree that this is a bug. The comparison that nobu made with `basename(1)` is relevant, but unlike `File.basename`, `basename(1)` does not handle `.*` specially. You can see that `basename(1)` does actually strip the extension even for multiple leading periods:
```
basename '..*' '.*'
..
```
Attached is a patch that fixes the issue, both for `File.basename` and `File.extname`. With the patch:
```ruby
File.basename('..jpg', '.*')
# => "."
File.extname('..jpg')
# => ".jpg"
```
----------------------------------------
Bug #15244: Method #extname return empty string if filename is dot ('.')
https://bugs.ruby-lang.org/issues/15244#change-80724
* Author: TiSer (Sergey TiSer)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: 2.7.0dev
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
### Example 1:
Current behaviour:
```
File.extname('..jpg')
=> ""
```
Expected behaviour:
```
File.extname('..jpg')
=> ".jpg"
```
### Example 2:
Current behaviour:
```
File.extname('....jpg')
=> ""
```
Expected behaviour:
```
=> ".jpg"
```
---Files--------------------------------
dot-names.diff (891 Bytes)
multiple-leading-dot-basename-extname-15244.patch (1.94 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>