From 670dd4179ea4d2b801f0e1f7bd8a6a70c3dacd57 Mon Sep 17 00:00:00 2001 From: Alexandru Emil Lupu Date: Sat, 9 May 2026 08:42:23 +0300 Subject: [PATCH 1/3] Add spec for temp file --- spec/unpack_odt_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/unpack_odt_spec.rb b/spec/unpack_odt_spec.rb index f3e9f0d..4ef70d0 100644 --- a/spec/unpack_odt_spec.rb +++ b/spec/unpack_odt_spec.rb @@ -17,4 +17,23 @@ def rspec_extract_odt rspec_extract_odt rspec_extract_odt end + + context "when the odt is a temporary file" do + it "runs from a temp file" do + tempfile = Tempfile.new('text_styles.odt') + tempfile.write File.read(File.join 'spec', 'fixtures', 'text_styles.odt') + tempfile.rewind + tempfile.close + + @odt = Doc2Text::Odt::Document.new tempfile + @odt.unpack + + entries = Dir.glob "#{@odt.extract_path}/**/*" + mandatory_files = %w(manifest.rdf content.xml settings.xml styles.xml META-INF META-INF/manifest.xml meta.xml mimetype).map { |entry| + File.join @odt.extract_path, entry } + expect(entries.to_set.subset? mandatory_files.to_set) + + @odt.clean + end + end end From 2440bad554f9491053398ca98b0caf34f3507395 Mon Sep 17 00:00:00 2001 From: Valentin Aitken Date: Wed, 13 May 2026 15:48:42 +0300 Subject: [PATCH 2/3] Fix extract path --- lib/doc2text/xml_based_document_file.rb | 8 ++++---- spec/unpack_odt_spec.rb | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/doc2text/xml_based_document_file.rb b/lib/doc2text/xml_based_document_file.rb index e0a6695..c6162aa 100644 --- a/lib/doc2text/xml_based_document_file.rb +++ b/lib/doc2text/xml_based_document_file.rb @@ -12,9 +12,9 @@ def unpack |zip_file| Dir.mkdir(extract_path) zip_file.each do |entry| - zipped_file_extract_path = File.join extract_path, entry.name - FileUtils.mkdir_p File.dirname(zipped_file_extract_path) - zip_file.extract entry, zipped_file_extract_path + zipped_file_extract_path = File.join extract_path, File.dirname(entry.name) + FileUtils.mkdir_p zipped_file_extract_path + zip_file.extract entry, nil, destination_directory: extract_path end } end @@ -41,7 +41,7 @@ def extract_extension end def extract_path - File.join File.dirname(@document_path), ".#{File.basename(@document_path)}_#{extract_extension}" + @extract_path ||= File.join File.dirname(@document_path), ".#{File.basename(@document_path)}_#{extract_extension}" end end end diff --git a/spec/unpack_odt_spec.rb b/spec/unpack_odt_spec.rb index 4ef70d0..bccb657 100644 --- a/spec/unpack_odt_spec.rb +++ b/spec/unpack_odt_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'tempfile' describe 'odt' do def rspec_extract_odt @@ -31,8 +32,9 @@ def rspec_extract_odt entries = Dir.glob "#{@odt.extract_path}/**/*" mandatory_files = %w(manifest.rdf content.xml settings.xml styles.xml META-INF META-INF/manifest.xml meta.xml mimetype).map { |entry| File.join @odt.extract_path, entry } - expect(entries.to_set.subset? mandatory_files.to_set) + expect(mandatory_files.to_set).to be_subset(entries.to_set) + tempfile.unlink @odt.clean end end From 1e8bf46a2f48dde19c13e149da6e05726d0287c9 Mon Sep 17 00:00:00 2001 From: Valentin Aitken Date: Wed, 13 May 2026 15:50:30 +0300 Subject: [PATCH 3/3] Upgrade gem version to 0.4.11 extract path fix --- doc2text.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc2text.gemspec b/doc2text.gemspec index b3f09b4..9a647eb 100644 --- a/doc2text.gemspec +++ b/doc2text.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'doc2text' - s.version = '0.4.10' + s.version = '0.4.11' s.authors = 'Valentin A.' s.email = 'valentin@nalisbg.com' s.homepage = 'http://doc2text.com'