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

Fix invalid encoding error for CSV #372

Merged
merged 2 commits into from
Jan 4, 2017
Merged
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
4 changes: 2 additions & 2 deletions lib/roo/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ def each_row_using_tempdir

def set_row_count(sheet)
@first_row[sheet] = 1
@last_row[sheet] = ::CSV.readlines(@filename).size
@last_row[sheet] = ::CSV.readlines(@filename, csv_options).size
@last_row[sheet] = @first_row[sheet] if @last_row[sheet].zero?

nil
end

def set_column_count(sheet)
@first_column[sheet] = 1
@last_column[sheet] = (::CSV.readlines(@filename).first || []).size
@last_column[sheet] = (::CSV.readlines(@filename, csv_options).first || []).size
@last_column[sheet] = @first_column[sheet] if @last_column[sheet].zero?

nil
Expand Down
2 changes: 2 additions & 0 deletions test/files/iso_8859_1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sic_reference;category_fr;category_de;brand;title_fr;title_de;description_fr;description_de;;;;;;;;;;;
MI-12005WC;Montres;Uhren;Miabelle;"Miramar; cuir blanc";"Miramar; Leder Weiss";"<p>L'ͩlͩgance redͩfinie. Ce mod��le Miabelle ne laisse pas indiffͩrent. La forme extravagante de cette montre est une exclusivitͩ Miabelle. Idͩalement con�_u pour les poignets fͩminins; il s'adapte parfaitement �_ toutes les tenues et les embellit. De forme ovale; ce mod��le est pourvu d'ͩlͩments Swarovski disposͩs sur une couronne ͩtincelante. 4 vͩritables diamants viennent parfaire le cadran nacrͩ. C'est l�_ le secret de cette brillance ͩclatante.</p><ul><li>Mod��le: Miramar </li><li>Bo͌tier en rhodium plaquͩ</li><li>Mouvement: Quartz</li><li>Diam��tre: 23mm</li><li>ATM: 5</li><li>Bracelet: Cuir blanc</li><li>Cadran: Blanc et rond en acier inoxydable avec Logo et aiguilles. </li><li>Fonction: Dateur</li><li>Swarovski Elements: 52 pi��ces</li><li>Diamants: 4 pi��ces</li></ul><p>Garantie 2 ans</p>";"<p>Eleganz erf�_hrt eine ganz neue Dimension. Dieses Modell von Miabelle l�_sst alle Herzen h�_her schlagen. Die kreative Form des Geh�_uses ist ein echtes Designhighlight und sucht seines Gleichen. Betont wird die ovale Form durch einen leuchtenden Kranz aus funkelnden Swarovski-Elementen; die perfekt von dem hochgl�_nzenden Geh�_use umrahmt werden. Vier Diamanten schm�_cken das Ziffernblatt und werden von echtem Perlmutt hinterlegt. So strahlt diese Uhr einen unvergleichlichen Glanz aus; der alle Blicke auf sich zieht.</p><ul><li>Modell: Miramar </li><li>Geh�_use aus Edelstahl</li><li>Uhrwerk: Quartz</li><li>Durchmesser: 23mm</li><li>ATM: 5</li><li>Armband: Leder weiss</li><li>Zifferblatt: weiss und rund aus Edelstahl mit Logo. </li><li>Funktion: Datumanzeige</li><li>Swarovski Elements: 52 St�_ck</li><li>Diamanten: 4 St�_ck</li></ul><p>Garantie 2 Jahre</p>";;;;;;;;;;;
8 changes: 8 additions & 0 deletions test/roo/test_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def test_csv_parsing_with_headers
assert_equal headers, parsed[1].keys
end

def test_iso_8859_1
file = File.open(File.join(TESTDIR, "iso_8859_1.csv"))
options = { csv_options: { col_sep: ";", encoding: Encoding::ISO_8859_1 } }
workbook = Roo::CSV.new(file.path, options)
result = workbook.last_column
assert_equal(19, result)
end

def roo_class
Roo::CSV
end
Expand Down