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

Use Zip::File#glob to match any document.xml #104

Merged
merged 1 commit into from
May 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/docx/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def initialize(path_or_io, options = {})
@zip = Zip::File.open_buffer(path_or_io)
end

document = @zip.find_entry('word/document.xml')
document ||= @zip.find_entry('word/document2.xml')
document = @zip.glob('word/document*.xml').first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the specification of Office Open XML file format.
Is there no docx file which have some xml files with prefix 'word/document'?
The PR #73 tries to deal with all the xml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specifications can be found here: http://officeopenxml.com/anatomyofOOXML.php


If we want to be more clean, we should load [Content_Types].xml and check the name of the document.

I will work on a new PR that will use [Content_Types].xml to define all XML.

raise Errno::ENOENT if document.nil?

@document_xml = document.get_input_stream.read
Expand Down