From 2d853e986f6691ee32e4923d7ebf69ca67b596e7 Mon Sep 17 00:00:00 2001 From: Tim Fischbach Date: Wed, 11 Nov 2026 11:10:30 +0100 Subject: [PATCH] Allow rubyzip 3 Version 3 interprets the first argument of Zip::Entry#extract as a path relative to a destination directory. Copy entry contents to the tempfile via the input stream instead, which works across versions. --- .../zip_entry_paperclip_io_adapter.rb | 4 +- pageflow-panorama.gemspec | 2 +- .../zip_entry_paperclip_io_adapter_spec.rb | 40 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 spec/pageflow/panorama/zip_entry_paperclip_io_adapter_spec.rb diff --git a/lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb b/lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb index 760c031..b0659c6 100644 --- a/lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb +++ b/lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb @@ -24,8 +24,8 @@ def cache_current_values end def copy_to_tempfile(entry) - override_existing_file = proc { true } - @entry.extract(destination.path, &override_existing_file) + entry.get_input_stream { |stream| IO.copy_stream(stream, destination) } + destination.rewind destination end end diff --git a/pageflow-panorama.gemspec b/pageflow-panorama.gemspec index de8fac2..249dd68 100644 --- a/pageflow-panorama.gemspec +++ b/pageflow-panorama.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.1' spec.add_runtime_dependency 'pageflow', ['>= 15.0', '< 18'] - spec.add_runtime_dependency 'rubyzip', '~> 1.1' + spec.add_runtime_dependency 'rubyzip', ['>= 1.1', '< 4'] spec.add_runtime_dependency 'aws-sdk-s3', '~> 1.17' spec.add_runtime_dependency 'pageflow-public-i18n', '~> 1.0' diff --git a/spec/pageflow/panorama/zip_entry_paperclip_io_adapter_spec.rb b/spec/pageflow/panorama/zip_entry_paperclip_io_adapter_spec.rb new file mode 100644 index 0000000..79c0839 --- /dev/null +++ b/spec/pageflow/panorama/zip_entry_paperclip_io_adapter_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +module Pageflow + module Panorama + describe ZipEntryPaperclipIOAdapter do + it 'is used for zip entries' do + Zip::File.open(Engine.root.join('spec', 'fixtures', 'some.txt.zip')) do |archive| + adapter = Paperclip.io_adapters.for(archive.find_entry('some.txt')) + + expect(adapter).to be_a(ZipEntryPaperclipIOAdapter) + end + end + + it 'provides contents of entry' do + Zip::File.open(Engine.root.join('spec', 'fixtures', 'some.txt.zip')) do |archive| + adapter = Paperclip.io_adapters.for(archive.find_entry('some.txt')) + + expect(adapter.read).to eq("text\n") + end + end + + it 'provides file name and size of entry' do + Zip::File.open(Engine.root.join('spec', 'fixtures', 'some.txt.zip')) do |archive| + adapter = Paperclip.io_adapters.for(archive.find_entry('some.txt')) + + expect(adapter.original_filename).to eq('some.txt') + expect(adapter.size).to eq(5) + end + end + + it 'detects content type of entry' do + Zip::File.open(Engine.root.join('spec', 'fixtures', 'some.txt.zip')) do |archive| + adapter = Paperclip.io_adapters.for(archive.find_entry('some.txt')) + + expect(adapter.content_type).to eq('text/plain') + end + end + end + end +end