Decouple load_rels from load_styles so @rels loads without styles.xml (#158)#178
Merged
Conversation
Previously load_rels was called from inside load_styles, so when a document had no word/styles.xml, load_styles raised Errno::ENOENT, was rescued, and load_rels never ran -- leaving @RELS nil. Any later call to #hyperlinks then crashed with "undefined method 'xpath' for nil". load_rels is now called independently from initialize and handles a missing rels file gracefully, so relationships load regardless of whether styles.xml is present. Adds a regression fixture (no_styles_with_hyperlink.docx: a document with a hyperlink relationship but no styles.xml) and a spec asserting #hyperlinks works in that case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #158. Relationships (and therefore hyperlinks) are now loaded independently of styles, so a document without
word/styles.xmlno longer leaves@relsuninitialized.The bug
load_relswas called from insideload_styles:When a document had no
word/styles.xml, the@zip.readraisedErrno::ENOENT, therescueswallowed it, andload_relsnever ran.@relsstayednil, so any later call to#hyperlinkscrashed:The fix
load_relsis now called directly frominitialize, independently ofload_styles.load_relsalso rescues a missing rels file gracefully (same pattern asload_styles), preserving the previous "swallow and warn" behavior for documents that genuinely have no rels.Tests
spec/fixtures/no_styles_with_hyperlink.docx— a document that has a hyperlink relationship but noword/styles.xml(derived fromformatting.docxwithword/styles.xmlremoved).#hyperlinksdoes not raise and returns{"rId4" => "http://www.google.com/"}for that document.master(NoMethodError) and passes with this change. Full suite green locally (146 examples, 0 failures).Closes #158
🤖 Generated with Claude Code