mime-types 2.99.3 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{Code-of-Conduct.rdoc → Code-of-Conduct.md} +29 -30
- data/Contributing.md +132 -0
- data/History.md +269 -0
- data/{Licence.rdoc → Licence.md} +4 -18
- data/Manifest.txt +8 -25
- data/README.rdoc +63 -73
- data/Rakefile +200 -97
- data/lib/mime/type/columnar.rb +30 -63
- data/lib/mime/type.rb +294 -458
- data/lib/mime/types/_columnar.rb +137 -0
- data/lib/mime/types/cache.rb +52 -74
- data/lib/mime/types/columnar.rb +2 -147
- data/lib/mime/types/container.rb +96 -0
- data/lib/mime/types/deprecations.rb +17 -34
- data/lib/mime/types/full.rb +19 -0
- data/lib/mime/types/loader.rb +36 -152
- data/lib/mime/types/logger.rb +7 -5
- data/lib/mime/types/registry.rb +90 -0
- data/lib/mime/types.rb +55 -148
- data/lib/mime-types.rb +2 -2
- data/test/minitest_helper.rb +8 -18
- data/test/test_mime_type.rb +489 -464
- data/test/test_mime_types.rb +139 -91
- data/test/test_mime_types_cache.rb +85 -57
- data/test/test_mime_types_class.rb +120 -100
- data/test/test_mime_types_lazy.rb +30 -28
- data/test/test_mime_types_loader.rb +18 -45
- metadata +92 -77
- data/Contributing.rdoc +0 -170
- data/History-Types.rdoc +0 -454
- data/History.rdoc +0 -590
- data/data/mime-types.json +0 -1
- data/data/mime.content_type.column +0 -1980
- data/data/mime.docs.column +0 -1980
- data/data/mime.encoding.column +0 -1980
- data/data/mime.friendly.column +0 -1980
- data/data/mime.obsolete.column +0 -1980
- data/data/mime.registered.column +0 -1980
- data/data/mime.signature.column +0 -1980
- data/data/mime.use_instead.column +0 -1980
- data/data/mime.xrefs.column +0 -1980
- data/docs/COPYING.txt +0 -339
- data/docs/artistic.txt +0 -127
- data/lib/mime/types/loader_path.rb +0 -15
- data/support/apache_mime_types.rb +0 -108
- data/support/benchmarks/load.rb +0 -64
- data/support/benchmarks/load_allocations.rb +0 -83
- data/support/benchmarks/object_counts.rb +0 -41
- data/support/convert/columnar.rb +0 -88
- data/support/convert.rb +0 -158
- data/support/iana_registry.rb +0 -172
@@ -1,139 +1,159 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "mime/types"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
|
-
|
6
|
+
describe MIME::Types, "registry" do
|
7
7
|
def setup
|
8
8
|
MIME::Types.send(:load_default_mime_types)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
describe "is enumerable" do
|
12
|
+
it "correctly uses an Enumerable method like #any?" do
|
13
|
+
assert(MIME::Types.any? { |type| type.content_type == "text/plain" })
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
MIME::Types.load_from_file(fn)
|
16
|
+
it "implements each with no parameters to return an Enumerator" do
|
17
|
+
assert_kind_of Enumerator, MIME::Types.each
|
18
|
+
assert_kind_of Enumerator, MIME::Types.map
|
21
19
|
end
|
22
|
-
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
21
|
+
it "will create a lazy enumerator" do
|
22
|
+
assert_kind_of Enumerator::Lazy, MIME::Types.lazy
|
23
|
+
assert_kind_of Enumerator::Lazy, MIME::Types.map.lazy
|
24
|
+
end
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
it "is countable with an enumerator" do
|
27
|
+
assert MIME::Types.each.count > 999
|
28
|
+
assert MIME::Types.lazy.count > 999
|
29
|
+
end
|
33
30
|
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
describe ".[]" do
|
33
|
+
it "can be searched with a MIME::Type" do
|
34
|
+
text_plain = MIME::Type.new("text/plain")
|
35
|
+
assert_includes MIME::Types[text_plain], "text/plain"
|
36
|
+
assert_equal 1, MIME::Types[text_plain].size
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
it "can be searched with a regular expression" do
|
40
|
+
assert_includes MIME::Types[/plain$/], "text/plain"
|
41
|
+
assert_equal 1, MIME::Types[/plain$/].size
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
it "sorts by priority with multiple matches" do
|
45
|
+
types = MIME::Types[/gzip$/].select { |t|
|
46
|
+
%w[application/gzip application/x-gzip multipart/x-gzip].include?(t)
|
47
|
+
}
|
48
|
+
# This is this way because of a new type ending with gzip that only
|
49
|
+
# appears in some data files.
|
50
|
+
assert_equal %w[application/gzip application/x-gzip multipart/x-gzip], types
|
51
|
+
assert_equal 3, types.size
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
it "can be searched with a string" do
|
55
|
+
assert_includes MIME::Types["text/plain"], "text/plain"
|
56
|
+
assert_equal 1, MIME::Types["text/plain"].size
|
58
57
|
end
|
59
|
-
end
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
it "can be searched with the complete flag" do
|
60
|
+
assert_empty MIME::Types[
|
61
|
+
"application/x-www-form-urlencoded",
|
62
|
+
complete: true
|
63
|
+
]
|
64
|
+
assert_includes MIME::Types["text/plain", complete: true], "text/plain"
|
65
|
+
assert_equal 1, MIME::Types["text/plain", complete: true].size
|
68
66
|
end
|
69
|
-
assert_empty(MIME::Types.type_for('zzz'))
|
70
|
-
end
|
71
67
|
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
it "can be searched with the registered flag" do
|
69
|
+
assert_empty MIME::Types["application/x-wordperfect6.1", registered: true]
|
70
|
+
refute_empty MIME::Types[
|
71
|
+
"application/x-www-form-urlencoded",
|
72
|
+
registered: true
|
73
|
+
]
|
74
|
+
refute_empty MIME::Types[/gzip/, registered: true]
|
75
|
+
refute_equal MIME::Types[/gzip/], MIME::Types[/gzip/, registered: true]
|
76
|
+
end
|
75
77
|
end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
describe ".type_for" do
|
80
|
+
it "finds all types for a given extension" do
|
81
|
+
assert_equal %w[application/gzip application/x-gzip],
|
82
|
+
MIME::Types.type_for("gz")
|
81
83
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
|
85
|
+
it "separates the extension from filenames" do
|
86
|
+
assert_equal %w[image/jpeg], MIME::Types.of(["foo.jpeg", "bar.jpeg"])
|
85
87
|
end
|
86
|
-
end
|
87
|
-
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
89
|
+
it "finds multiple extensions" do
|
90
|
+
assert_equal %w[image/jpeg text/plain],
|
91
|
+
MIME::Types.type_for(%w[foo.txt foo.jpeg])
|
92
|
+
end
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
94
|
+
it "does not find unknown extensions" do
|
95
|
+
assert_empty MIME::Types.type_for("zzz")
|
96
|
+
end
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
98
|
+
it "modifying type extensions causes reindexing" do
|
99
|
+
plain_text = MIME::Types["text/plain"].first
|
100
|
+
plain_text.add_extensions("xtxt")
|
101
|
+
assert_includes MIME::Types.type_for("xtxt"), "text/plain"
|
102
|
+
end
|
105
103
|
end
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
describe ".count" do
|
106
|
+
it "can count the number of types inside" do
|
107
|
+
assert MIME::Types.count > 999
|
108
|
+
end
|
110
109
|
end
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
MIME::Types.
|
111
|
+
describe ".add" do
|
112
|
+
def setup
|
113
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
114
|
+
MIME::Types.send(:load_default_mime_types)
|
115
|
+
end
|
116
|
+
|
117
|
+
let(:eruby) { MIME::Type.new("application/x-eruby") }
|
118
|
+
let(:jinja) { MIME::Type.new("application/jinja2") }
|
119
|
+
|
120
|
+
it "successfully adds a new type" do
|
121
|
+
MIME::Types.add(eruby)
|
122
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
115
123
|
end
|
116
|
-
|
117
|
-
|
124
|
+
|
125
|
+
it "complains about adding a duplicate type" do
|
126
|
+
MIME::Types.add(eruby)
|
127
|
+
assert_output "", /is already registered as a variant/ do
|
128
|
+
MIME::Types.add(eruby)
|
129
|
+
end
|
130
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
118
131
|
end
|
119
|
-
|
120
|
-
|
132
|
+
|
133
|
+
it "does not complain about adding a duplicate type when quiet" do
|
134
|
+
MIME::Types.add(eruby)
|
135
|
+
assert_silent do
|
136
|
+
MIME::Types.add(eruby, :silent)
|
137
|
+
end
|
138
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
121
139
|
end
|
122
|
-
end
|
123
140
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
MIME::Types
|
141
|
+
it "successfully adds from an array" do
|
142
|
+
MIME::Types.add([eruby, jinja])
|
143
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
144
|
+
assert_equal MIME::Types["application/jinja2"], [jinja]
|
128
145
|
end
|
129
|
-
assert_includes(MIME::Types['text/plain'], xtxp)
|
130
|
-
end
|
131
146
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
MIME::Types.
|
147
|
+
it "successfully adds from another MIME::Types" do
|
148
|
+
old_count = MIME::Types.count
|
149
|
+
|
150
|
+
mt = MIME::Types.new
|
151
|
+
mt.add(eruby)
|
152
|
+
|
153
|
+
MIME::Types.add(mt)
|
154
|
+
assert_equal old_count + 1, MIME::Types.count
|
155
|
+
|
156
|
+
assert_equal MIME::Types[eruby.content_type], [eruby]
|
136
157
|
end
|
137
|
-
assert_includes(MIME::Types.of('tzt'), xtxp)
|
138
158
|
end
|
139
159
|
end
|
@@ -1,28 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "mime/types"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
|
-
|
6
|
+
describe MIME::Types, "lazy loading" do
|
7
7
|
def setup
|
8
|
-
|
9
|
-
ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'true'
|
10
|
-
ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
|
11
|
-
MIME::Types::Cache.save
|
8
|
+
ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "true"
|
12
9
|
end
|
13
10
|
|
14
11
|
def teardown
|
15
|
-
clear_cache_file
|
16
12
|
reset_mime_types
|
17
|
-
|
18
|
-
FileUtils.rm ENV['RUBY_MIME_TYPES_CACHE']
|
19
|
-
ENV.delete('RUBY_MIME_TYPES_CACHE')
|
20
|
-
end
|
21
|
-
ENV.delete('RUBY_MIME_TYPES_LAZY_LOAD')
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear_cache_file
|
25
|
-
FileUtils.rm @cache_file if File.exist? @cache_file
|
13
|
+
ENV.delete("RUBY_MIME_TYPES_LAZY_LOAD")
|
26
14
|
end
|
27
15
|
|
28
16
|
def reset_mime_types
|
@@ -30,18 +18,32 @@ class TestMIMETypesLazy < Minitest::Test
|
|
30
18
|
MIME::Types.send(:load_default_mime_types)
|
31
19
|
end
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
describe ".lazy_load?" do
|
22
|
+
it "is true when RUBY_MIME_TYPES_LAZY_LOAD is set" do
|
23
|
+
assert_output "", /RUBY_MIME_TYPES_LAZY_LOAD/ do
|
24
|
+
assert_equal true, MIME::Types.send(:lazy_load?)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is nil when RUBY_MIME_TYPES_LAZY_LOAD is unset" do
|
29
|
+
ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = nil
|
30
|
+
assert_output "", "" do
|
31
|
+
assert_nil MIME::Types.send(:lazy_load?)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "is false when RUBY_MIME_TYPES_LAZY_LOAD is false" do
|
36
|
+
ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "false"
|
37
|
+
assert_output "", /RUBY_MIME_TYPES_LAZY_LOAD/ do
|
38
|
+
assert_equal false, MIME::Types.send(:lazy_load?)
|
39
|
+
end
|
40
|
+
end
|
39
41
|
end
|
40
42
|
|
41
|
-
|
43
|
+
it "loads lazily when RUBY_MIME_TYPES_LAZY_LOAD is set" do
|
42
44
|
MIME::Types.instance_variable_set(:@__types__, nil)
|
43
|
-
assert_nil
|
44
|
-
refute_nil
|
45
|
-
refute_nil
|
45
|
+
assert_nil MIME::Types.instance_variable_get(:@__types__)
|
46
|
+
refute_nil MIME::Types["text/html"].first
|
47
|
+
refute_nil MIME::Types.instance_variable_get(:@__types__)
|
46
48
|
end
|
47
49
|
end
|
@@ -1,59 +1,32 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "mime/types"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
|
-
|
6
|
+
describe MIME::Types::Loader do
|
7
7
|
def setup
|
8
|
-
@path
|
9
|
-
@loader
|
10
|
-
@bad_path = File.expand_path(
|
8
|
+
@path = File.expand_path("../fixture", __FILE__)
|
9
|
+
@loader = MIME::Types::Loader.new(@path)
|
10
|
+
@bad_path = File.expand_path("../bad-fixtures", __FILE__)
|
11
11
|
end
|
12
12
|
|
13
13
|
def assert_correctly_loaded(types)
|
14
|
-
assert_includes(types,
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
assert_deprecated('MIME::Type#urls') do
|
19
|
-
assert_empty types['audio/webm'].first.urls
|
20
|
-
end
|
21
|
-
assert_equal(%w(webm), types['audio/webm'].first.extensions)
|
22
|
-
refute(types['audio/webm'].first.registered?)
|
14
|
+
assert_includes(types, "application/1d-interleaved-parityfec")
|
15
|
+
assert_equal(%w[webm], types["audio/webm"].first.extensions)
|
16
|
+
refute(types["audio/webm"].first.registered?)
|
23
17
|
|
24
|
-
assert_equal(
|
25
|
-
|
18
|
+
assert_equal("Fixes a bug with IE6 and progressive JPEGs",
|
19
|
+
types["image/pjpeg"].first.docs)
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
assert_deprecated('MIME::Type#system') do
|
31
|
-
assert_nil types['application/x-apple-diskimage'].first.system
|
32
|
-
end
|
33
|
-
|
34
|
-
assert(types['audio/vnd.qcelp'].first.obsolete?)
|
35
|
-
assert_equal('audio/QCELP', types['audio/vnd.qcelp'].first.use_instead)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_load_yaml
|
39
|
-
assert_correctly_loaded(@loader.load_yaml)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_load_json
|
43
|
-
assert_correctly_loaded(@loader.load_json)
|
21
|
+
assert(types["audio/vnd.qcelp"].first.obsolete?)
|
22
|
+
assert_equal("audio/QCELP", types["audio/vnd.qcelp"].first.use_instead)
|
44
23
|
end
|
45
24
|
|
46
|
-
|
47
|
-
|
48
|
-
assert_correctly_loaded(@loader.load_v1)
|
49
|
-
end
|
25
|
+
it "loads YAML files correctly" do
|
26
|
+
assert_correctly_loaded @loader.load_yaml
|
50
27
|
end
|
51
28
|
|
52
|
-
|
53
|
-
|
54
|
-
assert_raises(MIME::Types::Loader::BadV1Format) {
|
55
|
-
MIME::Types::Loader.load_from_v1(File.join(@bad_path, 'malformed'))
|
56
|
-
}
|
57
|
-
}
|
29
|
+
it "loads JSON files correctly" do
|
30
|
+
assert_correctly_loaded @loader.load_json
|
58
31
|
end
|
59
32
|
end
|