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