From 3c2acc158dc7ef5e7bcd2963623104c32128bff7 Mon Sep 17 00:00:00 2001 From: PiTrem Date: Thu, 28 Mar 2024 17:34:47 +0100 Subject: [PATCH] fix: import collection export zip when directory entries present (#1841) * test: test import with modified zip (missing schema.json, rezipped) * fix: skip directory entries when parsing import collection zip --- lib/import/import_collections.rb | 4 ++++ spec/factories/attachments.rb | 6 ++++++ .../import/collection_samples_edited.zip | Bin 0 -> 6231 bytes spec/lib/import/import_collections_spec.rb | 5 +++-- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100755 spec/fixtures/import/collection_samples_edited.zip diff --git a/lib/import/import_collections.rb b/lib/import/import_collections.rb index a374b69b73..988f613b53 100644 --- a/lib/import/import_collections.rb +++ b/lib/import/import_collections.rb @@ -31,9 +31,13 @@ def extract att = Tempfile.new(encoding: 'ascii-8bit') att.write(@att.read_file) att.rewind + Zip::File.open(att.path) do |zip_file| # Handle entries one by one zip_file.each do |entry| + # do nothing for directory entry + next if entry.ftype == :directory + data = entry.get_input_stream.read.force_encoding('UTF-8') case entry.name when 'export.json' diff --git a/spec/factories/attachments.rb b/spec/factories/attachments.rb index d6c397b5b9..7d41b3c316 100644 --- a/spec/factories/attachments.rb +++ b/spec/factories/attachments.rb @@ -84,6 +84,12 @@ file_path { Rails.root.join('spec/fixtures/import/collection_samples.zip') } end + # copy of the collection_samples.zip file but with removed schema.json file + # and reziped (zip contains directory entries) + trait :with_edited_collection_zip do + file_path { Rails.root.join('spec/fixtures/import/collection_samples_edited.zip') } + end + trait :with_reaction_collection_zip do file_path { Rails.root.join('spec/fixtures/import/collection_reaction.zip') } end diff --git a/spec/fixtures/import/collection_samples_edited.zip b/spec/fixtures/import/collection_samples_edited.zip new file mode 100755 index 0000000000000000000000000000000000000000..9d3e68ce8bf0408680a883948bdc95ef6c7e3698 GIT binary patch literal 6231 zcmd6rbyQVbyT&(2cej!vpup}RB@_@rT0m+i-AYP#h#-h4sUVG{f;32j0wTF7rIZv! z0Rg$2;klppJD&Uh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