Skip to content

Document without word/_rels/document.xml.rels raises NoMethodError on #paragraphs #192

Closed

Description

@satoryu

Document#load_rels rescues a missing word/_rels/document*.xml.rels and leaves @rels nil. Afterwards, #hyperlink_relationships calls @rels.xpath without a nil check. That breaks #hyperlinks, #document_properties, and therefore #paragraphs / #tables / #to_s.

Repro (basic.docx with the rels part removed)

zip = Zip::File.open('spec/fixtures/basic.docx')
buf = Zip::OutputStream.write_buffer do |out|
  zip.each do |e|
    next if e.name.include?('_rels/document')
    out.put_next_entry(e.name)
    out.write(zip.read(e.name))
  end
end
doc = Docx::Document.open(buf.string)
doc.paragraphs
# => NoMethodError: undefined method 'xpath' for nil

Expected: a document without a relationships part opens and reads normally, and #hyperlinks returns {}. This mirrors the missing-styles.xml case fixed in #158.

Found while splitting the specs into per-class unit specs (#188).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions