Skip to content

Commit a41c287

Browse files
authored
Added support for single column csv with spaced header (#305)
nice catch!
1 parent 26ce300 commit a41c287

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/smarter_csv/auto_detection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def guess_column_separator(filehandle, options)
3232

3333
if candidates.values.max == 0
3434
# if the header only contains
35-
return ',' if line.chomp(options[:row_sep]) =~ /^\w+$/
35+
return ',' if line.chomp(options[:row_sep]) =~ /^[\w\s]+$/
3636

3737
raise SmarterCSV::NoColSepDetected
3838
end

spec/features/general/simple_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
end
1515
end
1616

17+
context 'when simple unix file with header with space' do
18+
let(:file) { "#{fixture_path}/simple_with_header_with_space.csv" }
19+
20+
it 'loads the csv file without issues' do
21+
expect(data.size).to eq 4 # should not raise
22+
end
23+
end
24+
1725
context 'when simple windows file with header' do
1826
let(:file) { "#{fixture_path}/simple_with_header_windows.csv" }
1927

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
user id
2+
1
3+
2
4+
3
5+
4

0 commit comments

Comments
 (0)