Skip to content

Commit

Permalink
Merge pull request #348 from ukolovda/name_with_leading_slash
Browse files Browse the repository at this point in the history
Fix open error if sheet name lead from slash (i.e. "/xl/worksheets/sheet.xml").
  • Loading branch information
stevendaniels committed Oct 13, 2016
2 parents 8ded0dc + f1bc6e6 commit cc0d1ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def extract_worksheet_rels(entries, path)
def extract_sheets_in_order(entries, sheet_ids, sheets, tmpdir)
(sheet_ids & sheets.keys).each_with_index do |id, i|
name = sheets[id]
entry = entries.find { |e| e.name =~ /#{name}$/ }
entry = entries.find { |e| "/#{e.name}" =~ /#{name}$/ }
path = "#{tmpdir}/roo_sheet#{i + 1}"
sheet_files << path
@sheet_files << path
Expand Down
Binary file added test/files/name_with_leading_slash.xlsx
Binary file not shown.
5 changes: 5 additions & 0 deletions test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2109,4 +2109,9 @@ def test_cleanup_on_error
with_each_spreadsheet(:name=>'non_existent_file', :ignore_errors=>true) do |oo|; end
assert_equal Dir.open(Dir.tmpdir).to_a, old_temp_files
end

def test_name_with_leading_slash
xlsx = Roo::Excelx.new(File.join(TESTDIR,'name_with_leading_slash.xlsx'))
assert_equal 1, xlsx.sheets.count
end
end # class

0 comments on commit cc0d1ec

Please sign in to comment.