Skip to content

Commit

Permalink
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
@@ -305,6 +305,9 @@ describe "File" do
File.join(["", "", "foo"]).should eq("foo")
File.join(["foo", "", "bar"]).should eq("foo/bar")
File.join(["foo", "", "", "bar"]).should eq("foo/bar")
File.join(["foo", "/", "bar"]).should eq("foo/bar")
File.join(["foo", "/", "/", "bar"]).should eq("foo/bar")
File.join(["/", "/foo", "/", "bar/", "/"]).should eq("/foo/bar/")
end

it "chown" do
6 changes: 4 additions & 2 deletions src/file.cr
Original file line number Diff line number Diff line change
@@ -721,9 +721,11 @@ class File < IO::FileDescriptor
def self.join(parts : Array | Tuple) : String
String.build do |str|
first = true
parts_last_index = parts.size - 1
parts.each_with_index do |part, index|
part.check_no_null_byte
next if part.empty? && index != parts.size - 1
next if part.empty? && index != parts_last_index
next if !first && index != parts_last_index && part == SEPARATOR_STRING

str << SEPARATOR unless first

@@ -735,7 +737,7 @@ class File < IO::FileDescriptor
byte_count -= 1
end

if index != parts.size - 1 && part.ends_with?(SEPARATOR)
if index != parts_last_index && part.ends_with?(SEPARATOR)
byte_count -= 1
end

0 comments on commit dd84ad0

Please sign in to comment.