Skip to content

Commit d7df855

Browse files
byrootSamSaffron
authored andcommitted
Handle MIME::Types differences on Windows
1 parent 192d72a commit d7df855

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

test/mini_mime_test.rb

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,64 @@ def should_prioritize_extensions_correctly
5656
end
5757

5858
if defined? MIME::Types
59-
def test_full_parity_with_mime_types
60-
skip("Windows MIME::Types isn't reliable") if RUBY_PLATFORM.match?(/windows/i)
59+
WINDOWS_TYPES = {
60+
"cu" => "application/cu-seeme",
61+
"ecma" => "application/ecmascript",
62+
"es" => "application/ecmascript",
63+
"jar" => "application/java-archive",
64+
"ser" => "application/java-serialized-object",
65+
"mp4" => "application/mp4",
66+
"mpg4" => "application/mp4",
67+
"doc" => "application/msword",
68+
"pgp" => "application/octet-stream",
69+
"gpg" => "application/octet-stream",
70+
"ai" => "application/pdf",
71+
"asc" => "application/pgp-signature",
72+
"rtf" => "application/rtf",
73+
"spp" => "application/scvp-vp-response",
74+
"sgml" => "application/sgml",
75+
"curl" => "application/vnd.curl",
76+
"odc" => "application/vnd.oasis.opendocument.chart",
77+
"odf" => "application/vnd.oasis.opendocument.formula",
78+
"odi" => "application/vnd.oasis.opendocument.image",
79+
"bdm" => "application/vnd.syncml.dm+wbxml",
80+
"dcr" => "application/x-director",
81+
"exe" => "application/x-ms-dos-executable",
82+
"wmz" => "application/x-ms-wmz",
83+
"cmd" => "application/x-msdos-program",
84+
"bat" => "application/x-msdos-program",
85+
"com" => "application/x-msdos-program",
86+
"reg" => "application/x-msdos-program",
87+
"ps1" => "application/x-msdos-program",
88+
"vbs" => "application/x-msdos-program",
89+
"pm" => "application/x-pagemaker",
90+
"xml" => "application/xml",
91+
"dtd" => "application/xml-dtd",
92+
"kar" => "audio/midi",
93+
"mid" => "audio/midi",
94+
"midi" => "audio/midi",
95+
"m4a" => "audio/mp4",
96+
"mp2" => "audio/mpeg",
97+
"ogg" => "audio/ogg",
98+
"wav" => "audio/wav",
99+
"webm" => "audio/webm",
100+
"wmv" => "audio/x-ms-wmv",
101+
"ra" => "audio/x-pn-realaudio",
102+
"hif" => "image/heic",
103+
"sub" => "image/vnd.dvb.subtitle",
104+
"xbm" => "image/x-xbitmap",
105+
"mts" => "model/vnd.mts",
106+
"rst" => "text/plain",
107+
}
61108

109+
def test_full_parity_with_mime_types
62110
exts = Set.new
63111
MIME::Types.each do |type|
64112
type.extensions.each { |ext| exts << ext }
65113
end
66114

115+
differences = []
116+
67117
exts.each do |ext|
68118
types = MIME::Types.type_for("a.#{ext}")
69119

@@ -75,8 +125,18 @@ def test_full_parity_with_mime_types
75125
# puts "#{ext} Expected #{type.content_type} Got #{MiniMime.lookup_by_filename("a.#{ext}").content_type}"
76126
# end
77127

78-
assert_equal type.content_type, MiniMime.lookup_by_filename("a.#{ext}").content_type
128+
expected = type.content_type
129+
if WINDOWS_TYPES.key?(ext) && RUBY_PLATFORM.match?(/mingw|windows/i)
130+
expected = WINDOWS_TYPES[ext]
131+
end
132+
actual = MiniMime.lookup_by_filename("a.#{ext}").content_type
133+
134+
if expected != actual
135+
differences << %{Expected ".#{ext}" to return #{expected.inspect}, got: #{actual.inspect}}
136+
end
79137
end
138+
139+
assert differences.empty?, differences.join("\n")
80140
end
81141
end
82142
end

0 commit comments

Comments
 (0)