Skip to content

Commit

Permalink
Fix: File.extname edge case for dot in path with no extension (#5790)
Browse files Browse the repository at this point in the history
  • Loading branch information
pblca authored and ysbaddaden committed Mar 9, 2018
1 parent f0bd6b6 commit 5a189cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/file_spec.cr
Expand Up @@ -290,6 +290,12 @@ describe "File" do
File.extname("/foo/bar/.profile").should eq("")
File.extname("/foo/bar/.profile.sh").should eq(".sh")
File.extname("/foo/bar/foo.").should eq("")
File.extname("/foo.bar/baz").should eq("")
File.extname("test.cr").should eq(".cr")
File.extname("test.cr.cz").should eq(".cz")
File.extname(".test").should eq("")
File.extname(".test.cr").should eq(".cr")
File.extname(".test.cr.cz").should eq(".cz")
File.extname("test").should eq("")
end

Expand Down
2 changes: 1 addition & 1 deletion src/file.cr
Expand Up @@ -298,7 +298,7 @@ class File < IO::FileDescriptor

dot_index = filename.rindex('.')

if dot_index && dot_index != filename.size - 1 && filename[dot_index - 1] != SEPARATOR
if dot_index && dot_index != filename.size - 1 && dot_index - 1 > (filename.rindex(SEPARATOR) || 0)
filename[dot_index, filename.size - dot_index]
else
""
Expand Down

0 comments on commit 5a189cb

Please sign in to comment.