mime-types 3.1 → 3.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.rdoc → Contributing.md} +63 -54
- data/History.md +196 -0
- data/{Licence.rdoc → Licence.md} +3 -3
- data/Manifest.txt +4 -4
- data/README.rdoc +5 -7
- data/Rakefile +5 -3
- data/lib/mime-types.rb +2 -0
- data/lib/mime/type.rb +9 -3
- data/lib/mime/type/columnar.rb +2 -0
- data/lib/mime/types.rb +7 -5
- data/lib/mime/types/_columnar.rb +2 -0
- data/lib/mime/types/cache.rb +2 -0
- data/lib/mime/types/columnar.rb +2 -0
- data/lib/mime/types/container.rb +41 -13
- data/lib/mime/types/deprecations.rb +4 -2
- data/lib/mime/types/full.rb +2 -0
- data/lib/mime/types/loader.rb +2 -4
- data/lib/mime/types/logger.rb +2 -0
- data/lib/mime/types/registry.rb +12 -3
- data/test/minitest_helper.rb +2 -0
- data/test/test_mime_type.rb +16 -3
- data/test/test_mime_types.rb +10 -0
- data/test/test_mime_types_cache.rb +15 -4
- data/test/test_mime_types_class.rb +2 -0
- data/test/test_mime_types_lazy.rb +11 -3
- data/test/test_mime_types_loader.rb +2 -0
- metadata +45 -33
- data/History.rdoc +0 -658
data/{Licence.rdoc → Licence.md}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
## Licence
|
2
2
|
|
3
|
-
* Copyright 2003–
|
3
|
+
* Copyright 2003–2018 Austin Ziegler and contributors.
|
4
4
|
|
5
5
|
The software in this repository is made available under the MIT license.
|
6
6
|
|
7
|
-
|
7
|
+
### MIT License
|
8
8
|
|
9
9
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
10
10
|
this software and associated documentation files (the "Software"), to deal in
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -41,9 +41,7 @@ mime-types 1.x is no longer supported as of 2015-10-27.
|
|
41
41
|
|
42
42
|
=== mime-types 2.x End of Life
|
43
43
|
|
44
|
-
mime-types 2.x is supported as
|
45
|
-
registry and security updates for two years. It will reach full end of life on
|
46
|
-
2017-11-21.
|
44
|
+
mime-types 2.x is no longer supported as of 2017-11-21.
|
47
45
|
|
48
46
|
=== mime-types 3.x
|
49
47
|
|
@@ -183,7 +181,7 @@ MAJOR.MINOR:
|
|
183
181
|
incremented, MINOR will be set to zero, and PATCH will be reset to the
|
184
182
|
implied zero.
|
185
183
|
|
186
|
-
2. If an API (code) feature is added that does not break
|
184
|
+
2. If an API (code) feature is added that does not break compatibility, the
|
187
185
|
MINOR version will be incremented and PATCH will be reset to the implied zero.
|
188
186
|
|
189
187
|
3. If there is a bugfix to a feature added in the most recent MAJOR.MINOR
|
@@ -195,8 +193,8 @@ features because of the existence of the [mime-types-data][] gem, and if
|
|
195
193
|
features are marked deprecated in the course of mime-types 3.x, they will not
|
196
194
|
be removed until mime-types 4.x or possibly later.
|
197
195
|
|
198
|
-
|
196
|
+
{Code of Conduct}[Code-of-Conduct_md.html]
|
199
197
|
|
200
|
-
|
198
|
+
{Contributing}[Contributing_md.html]
|
201
199
|
|
202
|
-
|
200
|
+
{Licence}[Licence_md.html]
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
require 'rubygems'
|
@@ -17,7 +19,7 @@ spec = Hoe.spec 'mime-types' do
|
|
17
19
|
|
18
20
|
require_ruby_version '>= 2.0'
|
19
21
|
|
20
|
-
self.history_file = 'History.
|
22
|
+
self.history_file = 'History.md'
|
21
23
|
self.readme_file = 'README.rdoc'
|
22
24
|
|
23
25
|
license 'MIT'
|
@@ -32,9 +34,9 @@ spec = Hoe.spec 'mime-types' do
|
|
32
34
|
extra_dev_deps << ['minitest', '~> 5.4']
|
33
35
|
extra_dev_deps << ['minitest-autotest', '~> 1.0']
|
34
36
|
extra_dev_deps << ['minitest-focus', '~> 1.0']
|
35
|
-
extra_dev_deps << ['minitest-bonus-assertions', '~>
|
37
|
+
extra_dev_deps << ['minitest-bonus-assertions', '~> 3.0']
|
36
38
|
extra_dev_deps << ['minitest-hooks', '~> 1.4']
|
37
|
-
extra_dev_deps << ['rake', '
|
39
|
+
extra_dev_deps << ['rake', '>= 10.0', '< 13.0']
|
38
40
|
extra_dev_deps << ['fivemat', '~> 1.3' ]
|
39
41
|
extra_dev_deps << ['minitest-rg', '~> 5.2']
|
40
42
|
|
data/lib/mime-types.rb
CHANGED
data/lib/mime/type.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
module MIME
|
3
5
|
end
|
@@ -55,7 +57,7 @@ class MIME::Type
|
|
55
57
|
end
|
56
58
|
|
57
59
|
# The released version of the mime-types library.
|
58
|
-
VERSION = '3.
|
60
|
+
VERSION = '3.2'
|
59
61
|
|
60
62
|
include Comparable
|
61
63
|
|
@@ -129,7 +131,11 @@ class MIME::Type
|
|
129
131
|
elsif other.respond_to?(:simplified)
|
130
132
|
simplified <=> other.simplified
|
131
133
|
else
|
132
|
-
|
134
|
+
filtered = 'silent' if other == :silent
|
135
|
+
filtered ||= 'true' if other == true
|
136
|
+
filtered ||= other.to_s
|
137
|
+
|
138
|
+
simplified <=> MIME::Type.simplified(filtered)
|
133
139
|
end
|
134
140
|
end
|
135
141
|
|
@@ -151,7 +157,7 @@ class MIME::Type
|
|
151
157
|
# before unregistered or obsolete content types.
|
152
158
|
def priority_compare(other)
|
153
159
|
pc = simplified <=> other.simplified
|
154
|
-
if pc.zero?
|
160
|
+
if pc.zero? || !(extensions & other.extensions).empty?
|
155
161
|
pc = if (reg = registered?) != other.registered?
|
156
162
|
reg ? -1 : 1 # registered < unregistered
|
157
163
|
elsif (comp = complete?) != other.complete?
|
data/lib/mime/type/columnar.rb
CHANGED
data/lib/mime/types.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
module MIME
|
3
5
|
##
|
@@ -149,7 +151,7 @@ class MIME::Types
|
|
149
151
|
def type_for(filename)
|
150
152
|
Array(filename).flat_map { |fn|
|
151
153
|
@extension_index[fn.chomp.downcase[/\.?([^.]*?)$/, 1]]
|
152
|
-
}.compact.inject(:+).sort { |a, b|
|
154
|
+
}.compact.inject(Set.new, :+).sort { |a, b|
|
153
155
|
a.priority_compare(b)
|
154
156
|
}
|
155
157
|
end
|
@@ -169,7 +171,7 @@ class MIME::Types
|
|
169
171
|
nil
|
170
172
|
when MIME::Types
|
171
173
|
variants = mime_type.instance_variable_get(:@type_variants)
|
172
|
-
add(*variants.values.inject(:+).to_a, quiet)
|
174
|
+
add(*variants.values.inject(Set.new, :+).to_a, quiet)
|
173
175
|
when Array
|
174
176
|
add(*mime_type, quiet)
|
175
177
|
else
|
@@ -195,7 +197,7 @@ Type #{type} is already registered as a variant of #{type.simplified}.
|
|
195
197
|
private
|
196
198
|
|
197
199
|
def add_type_variant!(mime_type)
|
198
|
-
@type_variants
|
200
|
+
@type_variants.add(mime_type.simplified, mime_type)
|
199
201
|
end
|
200
202
|
|
201
203
|
def reindex_extensions!(mime_type)
|
@@ -204,7 +206,7 @@ Type #{type} is already registered as a variant of #{type.simplified}.
|
|
204
206
|
end
|
205
207
|
|
206
208
|
def index_extensions!(mime_type)
|
207
|
-
mime_type.extensions.each { |ext| @extension_index
|
209
|
+
mime_type.extensions.each { |ext| @extension_index.add(ext, mime_type) }
|
208
210
|
end
|
209
211
|
|
210
212
|
def prune_matches(matches, complete, registered)
|
@@ -216,7 +218,7 @@ Type #{type} is already registered as a variant of #{type.simplified}.
|
|
216
218
|
def match(pattern)
|
217
219
|
@type_variants.select { |k, _|
|
218
220
|
k =~ pattern
|
219
|
-
}.values.inject(:+)
|
221
|
+
}.values.inject(Set.new, :+)
|
220
222
|
end
|
221
223
|
end
|
222
224
|
|
data/lib/mime/types/_columnar.rb
CHANGED
data/lib/mime/types/cache.rb
CHANGED
data/lib/mime/types/columnar.rb
CHANGED
data/lib/mime/types/container.rb
CHANGED
@@ -1,30 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
# MIME::Types requires a serializable keyed container that returns an empty Set
|
7
|
+
# on a key miss. Hash#default_value cannot be used because, while it traverses
|
8
|
+
# the Marshal format correctly, it won't survive any other serialization
|
9
|
+
# format (plus, a default of a mutable object resuls in a shared mess).
|
10
|
+
# Hash#default_proc cannot be used without a wrapper because it prevents
|
11
|
+
# Marshal serialization (and doesn't survive the round-trip).
|
12
|
+
class MIME::Types::Container #:nodoc:
|
13
|
+
extend Forwardable
|
2
14
|
|
3
|
-
# MIME::Types requires a container Hash with a default values for keys
|
4
|
-
# resulting in an empty array (<tt>[]</tt>), but this cannot be dumped through
|
5
|
-
# Marshal because of the presence of that default Proc. This class exists
|
6
|
-
# solely to satisfy that need.
|
7
|
-
class MIME::Types::Container < Hash # :nodoc:
|
8
15
|
def initialize
|
9
|
-
|
10
|
-
|
16
|
+
@container = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](key)
|
20
|
+
container[key] || EMPTY_SET
|
21
|
+
end
|
22
|
+
|
23
|
+
def_delegators :@container,
|
24
|
+
:count,
|
25
|
+
:each_value,
|
26
|
+
:keys,
|
27
|
+
:merge,
|
28
|
+
:merge!,
|
29
|
+
:select,
|
30
|
+
:values
|
31
|
+
|
32
|
+
def add(key, value)
|
33
|
+
(container[key] ||= Set.new).add(value)
|
11
34
|
end
|
12
35
|
|
13
36
|
def marshal_dump
|
14
|
-
{}.merge(
|
37
|
+
{}.merge(container)
|
15
38
|
end
|
16
39
|
|
17
40
|
def marshal_load(hash)
|
18
|
-
|
19
|
-
merge!(hash)
|
41
|
+
@container = hash
|
20
42
|
end
|
21
43
|
|
22
44
|
def encode_with(coder)
|
23
|
-
each { |k, v| coder[k] = v.to_a }
|
45
|
+
container.each { |k, v| coder[k] = v.to_a }
|
24
46
|
end
|
25
47
|
|
26
48
|
def init_with(coder)
|
27
|
-
|
28
|
-
coder.map.each { |k, v| self[k] = Set[*v] }
|
49
|
+
coder.map.each { |k, v| container[k] = Set[*v] }
|
29
50
|
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
attr_reader :container
|
55
|
+
|
56
|
+
EMPTY_SET = Set.new.freeze
|
57
|
+
private_constant :EMPTY_SET
|
30
58
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
require 'mime/types/logger'
|
@@ -23,9 +25,9 @@ module MIME
|
|
23
25
|
else
|
24
26
|
message
|
25
27
|
end
|
26
|
-
MIME::Types.logger.warn <<-
|
28
|
+
MIME::Types.logger.warn <<-WARNING.chomp
|
27
29
|
#{caller[1]}: #{klass}#{level}#{sym} is deprecated #{message}.
|
28
|
-
|
30
|
+
WARNING
|
29
31
|
block.call if block
|
30
32
|
end
|
31
33
|
end
|
data/lib/mime/types/full.rb
CHANGED
data/lib/mime/types/loader.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
##
|
@@ -31,10 +33,6 @@ class MIME::Types::Loader
|
|
31
33
|
path = path || ENV['RUBY_MIME_TYPES_DATA'] || MIME::Types::Data::PATH
|
32
34
|
@container = container || MIME::Types.new
|
33
35
|
@path = File.expand_path(path)
|
34
|
-
# begin
|
35
|
-
# require 'mime/lazy_types'
|
36
|
-
# @container.extend(MIME::LazyTypes)
|
37
|
-
# end
|
38
36
|
end
|
39
37
|
|
40
38
|
# Loads a MIME::Types registry from YAML files (<tt>*.yml</tt> or
|
data/lib/mime/types/logger.rb
CHANGED
data/lib/mime/types/registry.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class << MIME::Types
|
2
4
|
include Enumerable
|
3
5
|
|
@@ -41,7 +43,13 @@ class << MIME::Types
|
|
41
43
|
private
|
42
44
|
|
43
45
|
def lazy_load?
|
44
|
-
|
46
|
+
if ENV.key?('RUBY_MIME_TYPES_LAZY_LOAD')
|
47
|
+
MIME::Types.logger.warn <<-WARNING.chomp
|
48
|
+
Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed.
|
49
|
+
WARNING
|
50
|
+
|
51
|
+
(lazy = ENV['RUBY_MIME_TYPES_LAZY_LOAD']) && (lazy != 'false')
|
52
|
+
end
|
45
53
|
end
|
46
54
|
|
47
55
|
def __types__
|
@@ -55,8 +63,9 @@ class << MIME::Types
|
|
55
63
|
end
|
56
64
|
|
57
65
|
def load_default_mime_types(mode = load_mode)
|
58
|
-
@__types__ = MIME::Types::Cache.load
|
59
|
-
|
66
|
+
if @__types__ = MIME::Types::Cache.load
|
67
|
+
__instances__.add(@__types__)
|
68
|
+
else
|
60
69
|
@__types__ = MIME::Types::Loader.load(mode)
|
61
70
|
MIME::Types::Cache.save(@__types__)
|
62
71
|
end
|
data/test/minitest_helper.rb
CHANGED
data/test/test_mime_type.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
require 'mime/types'
|
@@ -330,21 +332,32 @@ describe MIME::Type do
|
|
330
332
|
assert_priority text_1, text_1p, text_2
|
331
333
|
end
|
332
334
|
|
333
|
-
it 'sorts (2) based on
|
335
|
+
it 'sorts (2) based on extensions' do
|
336
|
+
text_1.extensions = ["foo", "bar"]
|
337
|
+
text_2.extensions = ["foo"]
|
338
|
+
|
339
|
+
assert_priority_same text_1, text_2
|
340
|
+
|
341
|
+
text_2.registered = true
|
342
|
+
|
343
|
+
assert_priority_more text_1, text_2
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'sorts (3) based on the registration state' do
|
334
347
|
text_1.registered = text_1p.registered = true
|
335
348
|
text_1b = mime_type(text_1) { |t| t.registered = false }
|
336
349
|
|
337
350
|
assert_priority text_1, text_1p, text_1b
|
338
351
|
end
|
339
352
|
|
340
|
-
it 'sorts (
|
353
|
+
it 'sorts (4) based on the completeness' do
|
341
354
|
text_1.extensions = text_1p.extensions = '1'
|
342
355
|
text_1b = mime_type(text_1) { |t| t.extensions = nil }
|
343
356
|
|
344
357
|
assert_priority text_1, text_1p, text_1b
|
345
358
|
end
|
346
359
|
|
347
|
-
it 'sorts (
|
360
|
+
it 'sorts (5) based on obsolete status' do
|
348
361
|
text_1.obsolete = text_1p.obsolete = false
|
349
362
|
text_1b = mime_type(text_1) { |t| t.obsolete = true }
|
350
363
|
|
data/test/test_mime_types.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
require 'mime/types'
|
@@ -83,6 +85,12 @@ describe MIME::Types do
|
|
83
85
|
refute_empty mime_types[/gzip/, registered: true]
|
84
86
|
refute_equal mime_types[/gzip/], mime_types[/gzip/, registered: true]
|
85
87
|
end
|
88
|
+
|
89
|
+
it 'properly returns an empty result on a regular expression miss' do
|
90
|
+
assert_empty mime_types[/^foo/]
|
91
|
+
assert_empty mime_types[/^foo/, registered: true]
|
92
|
+
assert_empty mime_types[/^foo/, complete: true]
|
93
|
+
end
|
86
94
|
end
|
87
95
|
|
88
96
|
describe '#add' do
|
@@ -143,7 +151,9 @@ describe MIME::Types do
|
|
143
151
|
end
|
144
152
|
|
145
153
|
it 'does not find unknown extensions' do
|
154
|
+
keys = mime_types.instance_variable_get(:@extension_index).keys
|
146
155
|
assert_empty mime_types.type_for('zzz')
|
156
|
+
assert_equal keys, mime_types.instance_variable_get(:@extension_index).keys
|
147
157
|
end
|
148
158
|
|
149
159
|
it 'modifying type extensions causes reindexing' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- ruby encoding: utf-8 -*-
|
2
4
|
|
3
5
|
require 'mime/types'
|
@@ -35,11 +37,20 @@ describe MIME::Types::Cache do
|
|
35
37
|
describe '.load' do
|
36
38
|
it 'does not use cache when RUBY_MIME_TYPES_CACHE is unset' do
|
37
39
|
ENV.delete('RUBY_MIME_TYPES_CACHE')
|
38
|
-
|
40
|
+
assert_nil MIME::Types::Cache.load
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'does not use cache when missing' do
|
42
|
-
|
44
|
+
assert_nil MIME::Types::Cache.load
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'registers the data to be updated by #add_extensions' do
|
48
|
+
MIME::Types::Cache.save
|
49
|
+
reset_mime_types
|
50
|
+
assert_equal([], MIME::Types.type_for('foo.additional'))
|
51
|
+
html = MIME::Types['text/html'][0]
|
52
|
+
html.add_extensions('additional')
|
53
|
+
assert_equal([html], MIME::Types.type_for('foo.additional'))
|
43
54
|
end
|
44
55
|
|
45
56
|
it 'outputs an error when there is an invalid version' do
|
@@ -69,7 +80,7 @@ describe MIME::Types::Cache do
|
|
69
80
|
describe '.save' do
|
70
81
|
it 'does not create cache when RUBY_MIME_TYPES_CACHE is unset' do
|
71
82
|
ENV.delete('RUBY_MIME_TYPES_CACHE')
|
72
|
-
|
83
|
+
assert_nil MIME::Types::Cache.save
|
73
84
|
end
|
74
85
|
|
75
86
|
it 'creates the cache ' do
|
@@ -93,7 +104,7 @@ end
|
|
93
104
|
describe MIME::Types::Container do
|
94
105
|
it 'marshals and unmarshals correctly' do
|
95
106
|
container = MIME::Types::Container.new
|
96
|
-
container
|
107
|
+
container.add('xyz', 'abc')
|
97
108
|
|
98
109
|
# default proc should return Set[]
|
99
110
|
assert_equal(Set[], container['abc'])
|