summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorytjmt <[email protected]>2022-04-07 23:20:05 +0900
committerytjmt <[email protected]>2022-04-07 23:20:05 +0900
commitb6617ef71ef9980951f7eb30955ac73b7231e3a5 (patch)
tree1fa205edb4b3c30ec9fd56e5b4badc3773021a75
parent09c8f3fdd5d62918d59951697107b3b58ad24fb2 (diff)
downloadcaxlsx-b6617ef71ef9980951f7eb30955ac73b7231e3a5.tar.gz
caxlsx-b6617ef71ef9980951f7eb30955ac73b7231e3a5.zip
Sort archive entries for correct MIME detection with file command
-rw-r--r--lib/axlsx/package.rb8
-rw-r--r--test/tc_package.rb4
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 1b30c815..2faec2e3 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -206,12 +206,10 @@ module Axlsx
# @private
def parts
parts = [
- {:entry => RELS_PN, :doc => relationships, :schema => RELS_XSD},
{:entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD},
{:entry => CORE_PN, :doc => @core, :schema => CORE_XSD},
{:entry => APP_PN, :doc => @app, :schema => APP_XSD},
{:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD},
- {:entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD},
{:entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD}
]
@@ -256,7 +254,11 @@ module Axlsx
end
# Sort parts for correct MIME detection
- parts.sort_by { |part| part[:entry] }
+ [
+ {:entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD},
+ {:entry => RELS_PN, :doc => relationships, :schema => RELS_XSD},
+ *(parts.sort_by { |part| part[:entry] }.reverse)
+ ]
end
# Performs xsd validation for a signle document
diff --git a/test/tc_package.rb b/test/tc_package.rb
index b07f0d2f..6a943635 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -262,6 +262,10 @@ class TestPackage < Test::Unit::TestCase
#no mystery parts
assert_equal(25, p.size)
+ #sorted for correct MIME detection
+ assert_equal("[Content_Types].xml", p[0][:entry], "first entry should be `[Content_Types].xml`")
+ assert_equal("_rels/.rels", p[1][:entry], "second entry should be `_rels/.rels`")
+ assert_match(/\Axl\//, p[2][:entry], "third entry should begin with `xl/`")
end
def test_shared_strings_requires_part