From cdb719673351e10a3ce13b2a5deb151822593c27 Mon Sep 17 00:00:00 2001 From: Chi-Fung Fan Date: Fri, 5 May 2017 17:59:19 +0800 Subject: Sort archive entries for correct MIME detection --- lib/axlsx/package.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 8a4f29dc..5b5ea14a 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# encoding: utf-8 module Axlsx # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid # xlsx document including valdation and serialization. @@ -253,7 +253,9 @@ module Axlsx parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD} parts << {:entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD} end - parts + + # Sort parts for correct MIME detection + parts.sort_by { |part| part[:entry] } end # Performs xsd validation for a signle document -- cgit v1.2.3 From 274b53424a187f7e2ee583c035e7f32a217cf86e Mon Sep 17 00:00:00 2001 From: Chi-Fung Fan Date: Wed, 10 May 2017 03:12:27 +0800 Subject: Add spec coverage for correct MIME detection --- test/tc_helper.rb | 4 +++- test/tc_package.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/tc_helper.rb b/test/tc_helper.rb index 96f545cd..396f19b2 100644 --- a/test/tc_helper.rb +++ b/test/tc_helper.rb @@ -7,4 +7,6 @@ end require 'test/unit' require "timecop" -require "axlsx.rb" \ No newline at end of file +require "axlsx.rb" +# MIME detection for Microsoft Office 2007+ formats +require 'mimemagic/overlay' diff --git a/test/tc_package.rb b/test/tc_package.rb index 0ad27f7d..58ff53b0 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -154,6 +154,11 @@ class TestPackage < Test::Unit::TestCase assert package_1.to_stream.string == package_2.to_stream.string, "zip files are not identical" end + def test_serialization_creates_files_with_excel_mime_type + assert_equal(MimeMagic.by_magic(@package.to_stream).type, + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') + end + def test_validation assert_equal(@package.validate.size, 0, @package.validate) Axlsx::Workbook.send(:class_variable_set, :@@date1904, 9900) -- cgit v1.2.3