docx
docx copied to clipboard
Corrupted output file on v 0.10
Describe the bug
The saved file is corrupted on the latest version (0.10) but works on (0.9). Suspecting the change of the RubyZip 2.3 -> RubyZip 3.0 dependency but did not investigate further.
To Reproduce
Open a valid word docx document and immediately save it. Try to open the file with TextEdit on Mac.
example
# Open /path/to/your/docx/file.docx with TextEdit on MacOS, to make sure the file is valid.
require 'docx'
doc = Docx::Document.new('/path/to/your/docx/file.docx')
doc.save
# Then try to open /path/to/your/docx/file.docx with TextEdit on MacOS.
Sample docx file
Even a blank new document will do.
Expected behavior
After saving the new file should open with TextEdit as before.
Environment
- Ruby version: 3.4.2
docxgem version: regression from 0.9.0 (works) -> 0.10.0 (does not work)- OS: MacOS Tahoe
I am encountering this issue as well. This is the code I have been running in production for years, which stopped working in 0.10.0:
doc = Docx::Document.open(tmpfilename)
doc.paragraphs.each do |p|
p.text = '[was empty]' if p.text.empty? # replaced with <br> tags in postprocessing
end
doc.save(tmpfile_pp.path) # save modified version
The input DOCX is fine and opens correctly in Google Docs and in pandoc(1), but the output does not.