Skip to content
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

File.extname considers the whole path as a filename #5780

Closed
sudo-nice opened this issue Mar 6, 2018 · 5 comments
Closed

File.extname considers the whole path as a filename #5780

sudo-nice opened this issue Mar 6, 2018 · 5 comments

Comments

@sudo-nice
Copy link

puts File.extname("/foo.bar/baz")
Expected output: ""
Actual output: ".bar/baz"

Crystal 0.24.1

@straight-shoota
Copy link
Member

It's really disturbing this hasn't been noticed before...

Judging from the documentation it seems like this method is supposed to receive only a filename, not an entire path. So you'd be expected to use it as File.extname(File.basename("/foo.bar/baz")).
But that's not very intuitive and I don't think it makes sense this way.

@Sija
Copy link
Contributor

Sija commented Mar 6, 2018

In Ruby it returns nil. Just FYI.

@straight-shoota
Copy link
Member

@Sija That's a different thing, please open a new issue if you want to change that. File.extname always returns empty string if there is no extension.

@sudo-nice
Copy link
Author

@Sija In Ruby File.extname("/foo.bar/baz") will return an empty string. But puts will return nil, yes.

@ghost
Copy link

ghost commented Mar 7, 2018

So you'd be expected to use it as File.extname(File.basename("/foo.bar/baz")).
But that's not very intuitive and I don't think it makes sense this way.

Agreed - it must be a behaviour bug then.

The output ".bar/baz" can quite logically never be an "extension name". I don't
even know how "/" could ever be part of any extname so it sounds like a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants