Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/marcel/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2905,7 +2905,7 @@ module Marcel
['video/x-sgi-movie', [[0, b["MOVI\000"]], [0, b["MOVI\001"]], [0, b["MOVI\002"]], [0, b["MOVI\376"]], [0, b["MOVI\377"]]]],
['application/gzip', [[0, b["\037\213"]], [0, b["\037\213"]]]],
['application/zlib', [[0, b["x\001"]], [0, b['x^']], [0, b["x\234"]], [0, b["x\332"]]]],
['image/bmp;format=compressed', [[0, b['BM'], [[26, b["\001\000"], [[28, b["\000\000"]], [28, b["\001\000"]], [28, b["\004\000"]], [28, b["\b\000"]], [28, b["\020\000"]], [28, b["\030\000"]], [28, b[" \000"]]]]]]]],
['image/bmp', [[0, b['BM'], [[26, b["\001\000"], [[28, b["\000\000"]], [28, b["\001\000"]], [28, b["\004\000"]], [28, b["\b\000"]], [28, b["\020\000"]], [28, b["\030\000"]], [28, b[" \000"]]]]]]]],
['message/rfc822', [[0, nil, [[0, nil, [[0, b['Content-ID:']], [0, b['Content-Location:']], [0, b['Content-Transfer-Encoding:']], [0, b['Content-Type:']], [0, b['Date:']], [0, b['Delivered-To:']], [0, b['From:']], [0, b['Message-ID:']], [0, b['MIME-Version:']], [0, b['Received:']], [0, b['Relay-Version:']], [0, b['Return-Path:']], [0, b['Sent:']], [0, b['Status:']], [0, b['Subject:']], [0, b['To:']], [0, b['User-Agent:']], [0, b['X-Mailer:']], [0, b['X-Originating-IP:']], [0, b["\357\273\277"], [[3, b['Content-ID:']], [3, b['Content-Location:']], [3, b['Content-Transfer-Encoding:']], [3, b['Content-Type:']], [3, b['Date:']], [3, b['Delivered-To:']], [3, b['From:']], [3, b['Message-ID:']], [3, b['MIME-Version:']], [3, b['Received:']], [3, b['Relay-Version:']], [3, b['Return-Path:']], [3, b['Sent:']], [3, b['Status:']], [3, b['Subject:']], [3, b['To:']], [3, b['User-Agent:']], [3, b['X-Mailer:']], [3, b['X-Originating-IP:']]]]]], [0, nil, [[0..1024, b["\nContent-ID:"]], [0..1024, b["\nContent-Location:"]], [0..1024, b["\nContent-Transfer-Encoding:"]], [0..1024, b["\nContent-Type:"]], [0..1024, b["\nDate:"]], [0..1024, b["\nDelivered-To:"]], [0..1024, b["\nFrom:"]], [0..1024, b["\nMIME-Version:"]], [0..1024, b["\nReceived:"]], [0..1024, b["\nRelay-Version:"]], [0..1024, b["\nReturn-Path:"]], [0..1024, b["\nSent:"]], [0..1024, b["\nStatus:"]], [0..1024, b["\nSubject:"]], [0..1024, b["\nTo:"]], [0..1024, b["\nUser-Agent:"]], [0..1024, b["\nX-Mailer:"]], [0..1024, b["\nX-Originating-IP:"]], [0..1024, b["\nDKIM-"]], [0..1024, b["\nARC-"]]]]]]]],
['application/pdf', [[0..128, b['%%'], [[1..512, b['%PDF-1.']]]], [0..128, b['%%'], [[1..512, b['%PDF-2.']]]]]],
['application/vnd.wordperfect', [[0, b["\377WPC"]]]],
Expand Down
7 changes: 6 additions & 1 deletion script/generate_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def get_matches(mime, parent)
exit 1
end

TYPE_RENAMES = {
"image/bmp;format=compressed" => "image/bmp",
}.freeze

extensions = {}
types = {}
magics = []
Expand All @@ -214,7 +218,8 @@ def get_matches(mime, parent)

(doc/'mime-info/mime-type').each do |mime|
comments = Hash[*(mime/'_comment').map {|comment| [comment['xml:lang'], comment.inner_text] }.flatten]
type = mime['type']
type = TYPE_RENAMES[mime['type']] || mime['type']

subclass = (mime/'sub-class-of').map{|x| x['type']}
exts = (mime/'glob').map{|x| x['pattern'] =~ /^\*\.([^\[\]]+)$/ ? $1.downcase : nil }.compact
(mime/'magic').each do |magic|
Expand Down
2 changes: 1 addition & 1 deletion test/magic_and_declared_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Marcel::MimeType::MagicAndDeclaredTypeTest < Marcel::TestCase
each_content_type_fixture('name') do |file, name, content_type|
test "correctly returns #{content_type} for #{name} given both file and declared type" do
assert_equal content_type, raw_type(Marcel::MimeType.for(file, declared_type: content_type))
assert_equal content_type, Marcel::MimeType.for(file, declared_type: content_type)
end
end
end
2 changes: 1 addition & 1 deletion test/magic_and_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Marcel::MimeType::MagicAndNameTest < Marcel::TestCase
# generic type, while the name will choose a more specific subclass
each_content_type_fixture('name') do |file, name, content_type|
test "correctly returns #{content_type} for #{name} given both file and name" do
assert_equal content_type, raw_type(Marcel::MimeType.for(file, name: name))
assert_equal content_type, Marcel::MimeType.for(file, name: name)
end
end
end
2 changes: 1 addition & 1 deletion test/magic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Marcel::MimeType::MagicTest < Marcel::TestCase
# be recognised by magic alone; their name is also needed to correctly identify them.
each_content_type_fixture('magic') do |file, name, content_type|
test "gets type for #{content_type} by using only magic bytes #{name}" do
actual_type = raw_type(Marcel::MimeType.for(file))
actual_type = Marcel::MimeType.for(file)
assert_equal content_type, actual_type, "Expected #{file} to be #{content_type}, but was #{actual_type}"
end
end
Expand Down
4 changes: 0 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def each_content_type_fixture(folder)
end
end

def raw_type(content_type)
content_type.split(";").first
end

def files(name)
self.class.files(name)
end
Expand Down
Loading