Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple load rels method from load styles so that @rels variable can be initialized #158

Open
ThiagoAlves15 opened this issue Jan 21, 2025 · 0 comments
Labels

Comments

@ThiagoAlves15
Copy link

ThiagoAlves15 commented Jan 21, 2025

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
end

Sample 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)
  • docx gem version: ~> 0.8.0
  • OS: x86_64-linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant