Bug #15244
closedMethod #extname return empty string if filename is dot ('.')
Description
Files
Updated by TiSer (Sergey Ti) over 7 years ago
- Description updated (diff)
add one more example
Updated by shevegen (Robert A. Heiler) over 7 years ago
Is this a real problem?
How many people have had entries with more leading '.'?
It's not that I am not inclined to agree about it; I just think
it's a bit strange to want to change that behaviour. Do people
use lots of '.' for names to files or directories or symlinks?
Updated by ahorek (Pavel Rosický) over 7 years ago
Updated by TiSer (Sergey Ti) over 7 years ago
- Description updated (diff)
Updated by TiSer (Sergey Ti) over 7 years ago
Updated by nobu (Nobuyoshi Nakada) over 7 years ago
Updated by TiSer (Sergey Ti) over 7 years ago
This is still present.
Updated by TiSer (Sergey Ti) over 7 years ago
Still present.
Updated by TiSer (Sergey Ti) over 7 years ago
Still present.
Updated by rushsteve1 (Steven vanZyl) almost 7 years ago
- File dot-names.diff added
The issue seemed to be in how .dotfiles were handled, where all leading periods were trimmed when only the first should have been.
I've created a patch that seems to fix the issue and added a spect test for it. It's only a 2 line change.
This is my first patch submission so any and all feedback would be greatly appreciated.
Updated by rushsteve1 (Steven vanZyl) almost 7 years ago
- ruby -v changed from 2.5.0p0 to 2.7.0dev
Updated by rushsteve1 (Steven vanZyl) almost 7 years ago
- File dot-names.diff dot-names.diff added
Updated the diff to also account for the if (*p) case so that it will stop if p == 0.
Updated by rushsteve1 (Steven vanZyl) almost 7 years ago
- File deleted (
dot-names.diff)
Updated by jeremyevans0 (Jeremy Evans) almost 7 years ago
- Related to Bug #15267: File.basename + File.extname does not restore the original name added
Updated by jeremyevans0 (Jeremy Evans) almost 7 years ago
- File multiple-leading-dot-basename-extname-15244.patch 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:
Attached is a patch that fixes the issue, both for File.basename and File.extname. With the patch:
Updated by matz (Yukihiro Matsumoto) almost 7 years ago
- Status changed from Open to Feedback
.git is not an extension but a filename. .a.jpg has .jpg extension. I wonder how we can parse ..jpg. It's undefined behavior for me.
Any reasoning?
Matz.
Updated by znz (Kazuhiro NISHIYAMA) almost 7 years ago
In some other languages:
% python
Python 2.7.16 (default, Mar 4 2019, 09:01:38)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.splitext('..jpg')
('..jpg', '')
% python3
Python 3.7.4 (default, Jul 9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.splitext('..jpg')
('..jpg', '')
% php --version
PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
% php -r 'var_export(pathinfo("..jpg", PATHINFO_EXTENSION));'
'jpg'
ref https://hydrocul.github.io/wiki/programming_languages_diff/io/extname.html
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
znz (Kazuhiro NISHIYAMA) wrote:
Seems not for us:
Updated by TiSer (Sergey Ti) almost 7 years ago
Example from .NET:
(https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension)
Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
- Status changed from Feedback to Closed