Skip to content

Commit

Permalink
Fix Zlib error when loading from string
Browse files Browse the repository at this point in the history
Fixes load from string test to actually test loading from string.

Fixes woahdae#57 woahdae#58
  • Loading branch information
myabc committed May 3, 2024
1 parent 5eb0fa7 commit 78d1bb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/simple_xlsx_reader/loader/sheet_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ def parse(headers: false, &block)
@captured = nil # silence warnings
@dimension = nil # silence warnings

@file_io.rewind # in case we've already parsed this once

# In this project this is only used for GUI-made hyperlinks (as opposed
# to FUNCTION-based hyperlinks). Unfortunately the're needed to parse
# the spreadsheet, and they come AFTER the sheet data. So, solution is
# to just stream-parse the file twice, first for the hyperlinks at the
# bottom of the file, then for the file itself. In the future it would
# be clever to use grep to extract the xml into its own smaller file.
if xrels_file&.grep(/hyperlink/)&.any?
xrels_file.rewind
load_gui_hyperlinks # represented as hyperlinks_by_cell
if xrels_file
if xrels_file.grep(/hyperlink/).any?
xrels_file.rewind
load_gui_hyperlinks # represented as hyperlinks_by_cell
end
@file_io.rewind # we've already parsed this once
end

@file_io.rewind # in case we've already parsed this once

Nokogiri::XML::SAX::Parser.new(self).parse(@file_io)
end

Expand Down
2 changes: 1 addition & 1 deletion test/simple_xlsx_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
end

describe 'load from string' do
let(:subject) { SimpleXlsxReader.parse(sesame_street_blog_io) }
let(:subject) { SimpleXlsxReader.parse(sesame_street_blog_string) }

it 'reads an xlsx string into a hash of {[sheet name] => [data]}' do
_(subject.to_hash).must_equal(expected_result)
Expand Down

0 comments on commit 78d1bb3

Please sign in to comment.