Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/acsv/detect/separator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def self.separator(file_or_data)
firstline = file_or_data.readline
file_or_data.seek(position)
else
return nil if file_or_data.empty?

firstline = file_or_data.split("\n", 2)[0]
end

separators = SEPARATORS.map{|s| s.encode(firstline.encoding)}
sep = separators.map {|x| [firstline.count(x),x]}.sort_by {|x| x[0]}.last
sep[0] == 0 ? nil : sep[1].encode('ascii')
Expand Down
3 changes: 3 additions & 0 deletions spec/acsv/separator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
end
end

it 'handles empty string' do
expect(ACSV::Detect.separator('')).to be_nil
end
end
end