-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: path: should path.Ext() handle dotfiles specially? #24239
Comments
That's good design in my books. Less special cases are better. The definition of what a file extension is can then stay simple and that's desirable. |
I agree that the behavior is somewhat confusing if you're used to modern unix-like systems, which make heavy use of dotfiles. However, I think it's also worth pointing out that dotfiles are not special at all on some systems such as Windows, as they have a completely different definition of hidden files. With that in mind, I'm not sure it's a good idea for these APIs to handle dotfiles. For example, what should |
Playing my own devil's advocate - you could also argue that this isn't about dotfiles, but about filename extensions being a suffix to a non-empty name. That depends on how systems like Windows initerpret filenames like |
Considering that the concept of a file name extension is defined right there in the path.Ext docs, I think the current behaviour is fine and can't be changed anyway (for Go 1, at least).
|
Yeah, we can't chnnge this for Go 1, so this is by definition a Go 2 proposal. But I believe enough people on the Go team view dotfiles as horrible that I don't imagine they'd get much if any special support. |
The current |
What Go version, operating system and architecture are you using?
What did you do?
Call
path.Ext()
on various filenames that start with a dot. Complete example at https://play.golang.org/p/leXBZvbpbfjWhat did you expect to see?
path.Ext()
is meant to return the filename extension, which by convention specifies the file type. But if the very first character of the filename is a dot, that denotes a "hidden" file under Unix. Then the part after that dot is simply meant to denote the file's name, not its type. Altogether we have 4 cases:name
- normal file without extensionname.ext
- normal file with extension.name
- dotfile without extension.name.ext
- dotfile with extensionI expected
path.Ext()
not to return thename
part in any of these cases.What did you see instead?
As seen in the playground example,
path.Ext()
currently gives an intuitive result for all cases except 3. The implementation has no special handling for dotfiles so in case 3 it thinks the entire filename denotes an extension with the actual name part being blank.Python's
os.path.splitext()
handles dotfiles specially:It would seem reasonable to me for Go's
path.Ext()
to also have this behavior. What do others think?The text was updated successfully, but these errors were encountered: