Skip to content

Commit

Permalink
can read frozen string io
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril Champier committed May 23, 2019
1 parent 0ab10ae commit d1262ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/spreadsheet/excel/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1275,11 +1275,7 @@ def set_row_address worksheet, work, pos, len
end
def setup io
## Reading from StringIO fails without forced encoding
if io.respond_to?(:string) && (str = io.string) \
&& str.respond_to?(:force_encoding)
str.force_encoding 'ASCII-8BIT'
end
##
io.set_encoding('ASCII-8BIT') if io.respond_to?(:set_encoding)
io.rewind
@ole = Ole::Storage.open io
@workbook = Workbook.new io, {}
Expand Down
11 changes: 11 additions & 0 deletions test/excel/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def test_not_empty_file_error_on_setup
reader.setup not_empty_io
end
end

def test_not_frozen_stream_error_on_setup
reader = Spreadsheet::Excel::Reader.new
data = File.expand_path File.join('test', 'data')
path = File.join data, 'test_empty.xls'
content_string = File.read path
frozen_io = StringIO.new(content_string.freeze)
assert_nothing_thrown do
reader.setup(frozen_io)
end
end
end
end
end

0 comments on commit d1262ce

Please sign in to comment.