Commit 386b92d2 by Daniel Mendler Committed by GitHub

Merge pull request #64 from atambo/openxml

Handle Office Open XML types for filed generated outside MSOffice
parents b62d29d0 f4afc9ba
# Extra magic
[['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0, "PK\003\004", [[30, '[Content_Types].xml', [[0..5000, 'ppt/']]]]]]],
['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0, "PK\003\004", [[30, '[Content_Types].xml', [[0..5000, 'xl/']]]]]]],
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0, "PK\003\004", [[30, '[Content_Types].xml', [[0..5000, 'word/']]]]]]]].each do |magic|
[['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0, "PK\003\004", [[0..5000, '[Content_Types].xml', [[0..5000, 'ppt/']]]]]]],
['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0, "PK\003\004", [[0..5000, '[Content_Types].xml', [[0..5000, 'xl/']]]]]]],
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0, "PK\003\004", [[0..5000, '[Content_Types].xml', [[0..5000, 'word/']]]]]]]].each do |magic|
MimeMagic.add(magic[0], magic: magic[1])
end
......@@ -70,14 +70,17 @@ class TestMimeMagic < Minitest::Test
def test_recognize_xlsx_as_zip_without_magic
file = "test/files/application.vnd.openxmlformats-officedocument.spreadsheetml.sheet"
assert_equal "application/zip", MimeMagic.by_magic(File.read(file)).to_s
assert_equal "application/zip", MimeMagic.by_magic(File.open(file, 'rb')).to_s
%w(msoffice rubyxl gdocs).each do |variant|
file = "test/files/application.vnd.openxmlformats-officedocument.spreadsheetml{#{variant}}.sheet"
assert_equal "application/zip", MimeMagic.by_magic(File.read(file)).to_s
assert_equal "application/zip", MimeMagic.by_magic(File.open(file, 'rb')).to_s
end
end
def test_recognize_by_magic
load "mimemagic/overlay.rb"
Dir['test/files/*'].each do |file|
mime = file[11..-1].sub('.', '/')
mime = file[11..-1].sub('.', '/').sub(/\{\w+\}/, '')
assert_equal mime, MimeMagic.by_magic(File.read(file)).to_s
assert_equal mime, MimeMagic.by_magic(File.open(file, 'rb')).to_s
end
......@@ -85,9 +88,11 @@ class TestMimeMagic < Minitest::Test
def test_recognize_all_by_magic
load 'mimemagic/overlay.rb'
file = 'test/files/application.vnd.openxmlformats-officedocument.spreadsheetml.sheet'
mimes = %w[application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/zip]
assert_equal mimes, MimeMagic.all_by_magic(File.read(file)).map(&:type)
%w(msoffice rubyxl gdocs).each do |variant|
file = "test/files/application.vnd.openxmlformats-officedocument.spreadsheetml{#{variant}}.sheet"
mimes = %w[application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/zip]
assert_equal mimes, MimeMagic.all_by_magic(File.read(file)).map(&:type)
end
end
def test_have_add
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment