-
-
Notifications
You must be signed in to change notification settings - Fork 179
Description
Describe the bug
An error undefined method 'xpath' for nil:NilClass @rels.xpath("//xmlns:Relationship[contains(@Type,'hyperlink')]") is raised when the object fails to load the documents styles because the @rels variable did not load due to method coupling between load_rels and load_styles, making it so that if an error occurs when loading file styles the @rels variable is not loaded into the object.
To Reproduce
1- Create a .docx file with missing styles, so that load_styles method will return a No such file or directory - word/styles.xml message;
2- Try and access the paragraphs property of the loaded doc object with doc.paragraphs;
example
require 'docx'
doc = Docx::Document.new('/path/to/your/docx/file.docx')
doc.send(:load_styles)
# No such file or directory - word/styles.xml
doc.paragraphs.each do |p|
puts p
endSample docx file
Cannot add the sample due to having confidential information in it and I do not have the means to save a docx file that will preserve the broken style used in it.
Expected behavior
Expected to be able to parse the document's text without issue when style is not present.
Environment
- Ruby version: ruby 3.1.6p260 (2024-05-29 revision a777087be6)
docxgem version: ~> 0.8.0- OS: x86_64-linux