ruby-docx / docx

a ruby library/gem for interacting with .docx files
MIT License
439 stars 171 forks source link

ENOENT error because internal doc is word/document22.xml #103

Closed bmulholland closed 3 years ago

bmulholland commented 3 years ago

Describe the bug

I found a .docx file that appears to be completely valid (it opens in Word) but raises an error ENOENT when opening with this gem.

To Reproduce

Docx::Document.new with this file: weird_docx.docx

The code looks for word/document.xml and word/document2.xml but not word/document22.xml, which is what's inside this doc.

Isn't Word just obnoxious?

WaKeMaTTa commented 3 years ago

I created this fix https://github.com/ruby-docx/docx/pull/104

satoryu commented 3 years ago

@bmulholland the new version, v0.6.1 of docx gem has been released. it contains a bug fix (thank you, @WaKeMaTTa !) to fix this issue. please try it!

bmulholland commented 3 years ago

Amazing - thanks for the fast turnaround! I just got time to try it out, and the immediate issue is indeed solved. However, now we get a different error with the same file, just when we try to get the document's text.

I don't have time right now to dig in more, but can if needed.

Source:

    Docx::Document.open(file) do |doc|
      return doc.to_s
    end

Trace:

     NoMethodError:
       undefined method `xpath' for nil:NilClass
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:94:in `hyperlink_relationships'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:88:in `hyperlinks'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:48:in `document_properties'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:189:in `parse_paragraph_from'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:61:in `block in paragraphs'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/xml/node_set.rb:239:in `block in each'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/xml/node_set.rb:238:in `upto'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/nokogiri-1.11.3-x86_64-darwin/lib/nokogiri/xml/node_set.rb:238:in `each'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:61:in `map'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:61:in `paragraphs'
     # /Users/bmulholland/.rvm/gems/ruby-2.7.2@recital-backend/gems/docx-0.6.1/lib/docx/document.rb:110:in `to_s'
WaKeMaTTa commented 3 years ago

This weekend I will spend sometime improving lib/docx/document.rb following the DOCX structure.

bmulholland commented 3 years ago

Should I open a new issue for the crash I posted above?

WaKeMaTTa commented 3 years ago

This weekend I will spend sometime improving lib/docx/document.rb following the DOCX structure.

Sorry @bmulholland , I had a couple busy weeks. I didn't start this :top: .


Should I open a new issue for the crash I posted above?

Yeah, you should.

bmulholland commented 3 years ago

Nothing to apologize for - this project is free and I appreciate any work you do put in :). I ask just to make sure it doesn't fall off the radar.