mime-types 3.5.2 → 3.6.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Code-of-Conduct.md +99 -44
- data/History.md +18 -0
- data/README.rdoc +2 -1
- data/Rakefile +1 -0
- data/lib/mime/type.rb +68 -43
- data/lib/mime/types/container.rb +2 -2
- data/lib/mime/types/deprecations.rb +39 -19
- data/lib/mime/types/loader.rb +1 -1
- data/lib/mime/types/registry.rb +6 -4
- data/test/test_mime_type.rb +37 -33
- data/test/test_mime_types.rb +11 -16
- data/test/test_mime_types_class.rb +3 -3
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d32410a9932dbf1c1857f313b7881099d7bf97ea7f73002145fd1e769e0ab43e
|
4
|
+
data.tar.gz: c2edbde050f3f02cb2d6393a91dc31cf15360c4646452737ec8ceba7feb1831f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f1f6f88f8e4175dd598eebbe5daa7948c542af1416f7bcf0392d05323169c470055d376b4fcf62bc3f3d3cb7243c94f31fca7fd0a8f5e8e849b38cd67e53ee3
|
7
|
+
data.tar.gz: ed34529568fd07a33459e1d6bfe4bced23eaea76b46edf98c4b060a57672e173e33cc5c2c71539cd3ad99e9e2cd16e49c2ca8d9d3c67dd64dca3601bea823453
|
data/Code-of-Conduct.md
CHANGED
@@ -2,72 +2,127 @@
|
|
2
2
|
|
3
3
|
## Our Pledge
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
11
14
|
|
12
15
|
## Our Standards
|
13
16
|
|
14
|
-
Examples of behavior that contributes to
|
15
|
-
include:
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
16
19
|
|
17
|
-
-
|
18
|
-
- Being respectful of differing viewpoints and experiences
|
19
|
-
-
|
20
|
-
-
|
21
|
-
|
20
|
+
- Demonstrating empathy and kindness toward other people
|
21
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
- Giving and gracefully accepting constructive feedback
|
23
|
+
- Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
- Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
22
27
|
|
23
|
-
Examples of unacceptable behavior
|
28
|
+
Examples of unacceptable behavior include:
|
24
29
|
|
25
|
-
- The use of sexualized language or imagery and
|
26
|
-
|
27
|
-
- Trolling, insulting
|
30
|
+
- The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
28
33
|
- Public or private harassment
|
29
|
-
- Publishing others' private information, such as a physical or
|
30
|
-
|
34
|
+
- Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
31
36
|
- Other conduct which could reasonably be considered inappropriate in a
|
32
37
|
professional setting
|
33
38
|
|
34
|
-
##
|
39
|
+
## Enforcement Responsibilities
|
35
40
|
|
36
|
-
|
37
|
-
behavior and
|
38
|
-
response to any
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
39
45
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
threatening, offensive, or harmful.
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
45
50
|
|
46
51
|
## Scope
|
47
52
|
|
48
|
-
This Code of Conduct applies
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
representative at an online or offline event.
|
53
|
-
further defined and clarified by project maintainers.
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
54
58
|
|
55
59
|
## Enforcement
|
56
60
|
|
57
61
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported
|
59
|
-
complaints will be reviewed and investigated and
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
reported to the community leaders responsible for enforcement at [INSERT CONTACT
|
63
|
+
METHOD]. All complaints will be reviewed and investigated promptly and fairly.
|
64
|
+
|
65
|
+
All community leaders are obligated to respect the privacy and security of the
|
66
|
+
reporter of any incident.
|
67
|
+
|
68
|
+
## Enforcement Guidelines
|
69
|
+
|
70
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
71
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
72
|
+
|
73
|
+
### 1. Correction
|
74
|
+
|
75
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
76
|
+
unprofessional or unwelcome in the community.
|
77
|
+
|
78
|
+
**Consequence**: A private, written warning from community leaders, providing
|
79
|
+
clarity around the nature of the violation and an explanation of why the
|
80
|
+
behavior was inappropriate. A public apology may be requested.
|
81
|
+
|
82
|
+
### 2. Warning
|
83
|
+
|
84
|
+
**Community Impact**: A violation through a single incident or series of
|
85
|
+
actions.
|
63
86
|
|
64
|
-
|
65
|
-
|
66
|
-
|
87
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
88
|
+
interaction with the people involved, including unsolicited interaction with
|
89
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
90
|
+
includes avoiding interactions in community spaces as well as external channels
|
91
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
92
|
+
ban.
|
93
|
+
|
94
|
+
### 3. Temporary Ban
|
95
|
+
|
96
|
+
**Community Impact**: A serious violation of community standards, including
|
97
|
+
sustained inappropriate behavior.
|
98
|
+
|
99
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
100
|
+
communication with the community for a specified period of time. No public or
|
101
|
+
private interaction with the people involved, including unsolicited interaction
|
102
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
103
|
+
Violating these terms may lead to a permanent ban.
|
104
|
+
|
105
|
+
### 4. Permanent Ban
|
106
|
+
|
107
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
108
|
+
standards, including sustained inappropriate behavior, harassment of an
|
109
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
110
|
+
|
111
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
112
|
+
community.
|
67
113
|
|
68
114
|
## Attribution
|
69
115
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
71
|
-
available at
|
116
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
117
|
+
version 2.1, available at
|
118
|
+
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.
|
119
|
+
|
120
|
+
Community Impact Guidelines were inspired by
|
121
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
122
|
+
|
123
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
124
|
+
<https://www.contributor-covenant.org/faq>. Translations are available at
|
125
|
+
<https://www.contributor-covenant.org/translations>.
|
72
126
|
|
73
127
|
[homepage]: https://www.contributor-covenant.org
|
128
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
data/History.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 3.6 / 2024-09-30
|
4
|
+
|
5
|
+
- 2 deprecations:
|
6
|
+
|
7
|
+
- Array-based MIME::Type initialization
|
8
|
+
- String-based MIME::Type initialization
|
9
|
+
|
10
|
+
Use of these these will result in deprecation warnings.
|
11
|
+
|
12
|
+
- Added `logger` to the gemspec to suppress a bundled gem warning with Ruby
|
13
|
+
3.3.5. This warning should not be showing up until Ruby 3.4.0 is released and
|
14
|
+
will be suppressed in Ruby 3.3.6.
|
15
|
+
|
16
|
+
- Reworked the deprecation message code to be somewhat more flexible and allow
|
17
|
+
for outputting certain warnings once. Because there will be at least one other
|
18
|
+
release after 3.6, we do not need to make the type initialization deprecations
|
19
|
+
frequent with this release.
|
20
|
+
|
3
21
|
## 3.5.2 / 2024-01-02
|
4
22
|
|
5
23
|
There are no primary code changes, but we are releasing this as an update as
|
data/README.rdoc
CHANGED
@@ -183,7 +183,8 @@ MAJOR.MINOR:
|
|
183
183
|
MAJOR.MINOR.PATCH.
|
184
184
|
|
185
185
|
In practical terms, there will be fewer releases of mime-types focussing on
|
186
|
-
features because of the existence of the
|
186
|
+
features because of the existence of the
|
187
|
+
{mime-types-data}[https://github.com/mime-types/mime-types-data] gem, and if
|
187
188
|
features are marked deprecated in the course of mime-types 3.x, they will not
|
188
189
|
be removed until mime-types 4.x or possibly later.
|
189
190
|
|
data/Rakefile
CHANGED
@@ -22,6 +22,7 @@ spec = Hoe.spec "mime-types" do
|
|
22
22
|
spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" }
|
23
23
|
|
24
24
|
extra_deps << ["mime-types-data", "~> 3.2015"]
|
25
|
+
extra_deps << ["logger", ">= 0"]
|
25
26
|
|
26
27
|
extra_dev_deps << ["hoe", ">= 3.0", "< 5"]
|
27
28
|
extra_dev_deps << ["hoe-doofus", "~> 1.0"]
|
data/lib/mime/type.rb
CHANGED
@@ -4,20 +4,22 @@
|
|
4
4
|
module MIME
|
5
5
|
end
|
6
6
|
|
7
|
+
require "mime/types/deprecations"
|
8
|
+
|
7
9
|
# The definition of one MIME content-type.
|
8
10
|
#
|
9
11
|
# == Usage
|
10
|
-
# require
|
12
|
+
# require "mime/types"
|
11
13
|
#
|
12
|
-
# plaintext = MIME::Types[
|
14
|
+
# plaintext = MIME::Types["text/plain"] # => [ text/plain ]
|
13
15
|
# text = plaintext.first
|
14
|
-
# puts text.media_type # =>
|
15
|
-
# puts text.sub_type # =>
|
16
|
+
# puts text.media_type # => "text"
|
17
|
+
# puts text.sub_type # => "plain"
|
16
18
|
#
|
17
|
-
# puts text.extensions.join(
|
18
|
-
# puts text.preferred_extension # =>
|
19
|
-
# puts text.friendly # =>
|
20
|
-
# puts text.i18n_key # =>
|
19
|
+
# puts text.extensions.join(" ") # => "txt asc c cc h hh cpp hpp dat hlp"
|
20
|
+
# puts text.preferred_extension # => "txt"
|
21
|
+
# puts text.friendly # => "Text Document"
|
22
|
+
# puts text.i18n_key # => "text.plain"
|
21
23
|
#
|
22
24
|
# puts text.encoding # => quoted-printable
|
23
25
|
# puts text.default_encoding # => quoted-printable
|
@@ -28,45 +30,45 @@ end
|
|
28
30
|
# puts text.provisional? # => false
|
29
31
|
# puts text.complete? # => true
|
30
32
|
#
|
31
|
-
# puts text # =>
|
33
|
+
# puts text # => "text/plain"
|
32
34
|
#
|
33
|
-
# puts text ==
|
34
|
-
# puts
|
35
|
-
# puts text ==
|
36
|
-
# puts
|
35
|
+
# puts text == "text/plain" # => true
|
36
|
+
# puts "text/plain" == text # => true
|
37
|
+
# puts text == "text/x-plain" # => false
|
38
|
+
# puts "text/x-plain" == text # => false
|
37
39
|
#
|
38
|
-
# puts MIME::Type.simplified(
|
39
|
-
# puts MIME::Type.i18n_key(
|
40
|
+
# puts MIME::Type.simplified("x-appl/x-zip") # => "x-appl/x-zip"
|
41
|
+
# puts MIME::Type.i18n_key("x-appl/x-zip") # => "x-appl.x-zip"
|
40
42
|
#
|
41
|
-
# puts text.like?(
|
42
|
-
# puts text.like?(MIME::Type.new(
|
43
|
+
# puts text.like?("text/x-plain") # => true
|
44
|
+
# puts text.like?(MIME::Type.new("content-type" => "x-text/x-plain")) # => true
|
43
45
|
#
|
44
46
|
# puts text.xrefs.inspect # => { "rfc" => [ "rfc2046", "rfc3676", "rfc5147" ] }
|
45
47
|
# puts text.xref_urls # => [ "http://www.iana.org/go/rfc2046",
|
46
48
|
# # "http://www.iana.org/go/rfc3676",
|
47
49
|
# # "http://www.iana.org/go/rfc5147" ]
|
48
50
|
#
|
49
|
-
# xtext = MIME::Type.new(
|
50
|
-
# puts xtext.media_type # =>
|
51
|
-
# puts xtext.raw_media_type # =>
|
52
|
-
# puts xtext.sub_type # =>
|
53
|
-
# puts xtext.raw_sub_type # =>
|
51
|
+
# xtext = MIME::Type.new("x-text/x-plain")
|
52
|
+
# puts xtext.media_type # => "text"
|
53
|
+
# puts xtext.raw_media_type # => "x-text"
|
54
|
+
# puts xtext.sub_type # => "plain"
|
55
|
+
# puts xtext.raw_sub_type # => "x-plain"
|
54
56
|
# puts xtext.complete? # => false
|
55
57
|
#
|
56
|
-
# puts MIME::Types.any? { |type| type.content_type ==
|
58
|
+
# puts MIME::Types.any? { |type| type.content_type == "text/plain" } # => true
|
57
59
|
# puts MIME::Types.all?(&:registered?) # => false
|
58
60
|
#
|
59
61
|
# # Various string representations of MIME types
|
60
|
-
# qcelp = MIME::Types[
|
61
|
-
# puts qcelp.content_type # =>
|
62
|
-
# puts qcelp.simplified # =>
|
62
|
+
# qcelp = MIME::Types["audio/QCELP"].first # => audio/QCELP
|
63
|
+
# puts qcelp.content_type # => "audio/QCELP"
|
64
|
+
# puts qcelp.simplified # => "audio/qcelp"
|
63
65
|
#
|
64
|
-
# xwingz = MIME::Types[
|
65
|
-
# puts xwingz.content_type # =>
|
66
|
-
# puts xwingz.simplified # =>
|
66
|
+
# xwingz = MIME::Types["application/x-Wingz"].first # => application/x-Wingz
|
67
|
+
# puts xwingz.content_type # => "application/x-Wingz"
|
68
|
+
# puts xwingz.simplified # => "application/x-wingz"
|
67
69
|
class MIME::Type
|
68
70
|
# Reflects a MIME content-type specification that is not correctly
|
69
|
-
# formatted (it
|
71
|
+
# formatted (it is not +type+/+subtype+).
|
70
72
|
class InvalidContentType < ArgumentError
|
71
73
|
# :stopdoc:
|
72
74
|
def initialize(type_string)
|
@@ -93,14 +95,20 @@ class MIME::Type
|
|
93
95
|
end
|
94
96
|
|
95
97
|
# The released version of the mime-types library.
|
96
|
-
VERSION = "3.
|
98
|
+
VERSION = "3.6.0.beta1"
|
97
99
|
|
98
100
|
include Comparable
|
99
101
|
|
100
102
|
# :stopdoc:
|
101
|
-
#
|
102
|
-
#
|
103
|
-
|
103
|
+
# Full conformance with RFC 6838 §4.2 (the recommendation for < 64 characters is not
|
104
|
+
# enforced or reported because MIME::Types mostly deals with registered data). RFC 4288
|
105
|
+
# §4.2 does not restrict the first character to alphanumeric, but the total length of
|
106
|
+
# each part is limited to 127 characters. RFCC 2045 §5.1 does not restrict the character
|
107
|
+
# composition except for whitespace, but MIME::Type was always more strict than this.
|
108
|
+
restricted_name_first = "[0-9a-zA-Z]"
|
109
|
+
restricted_name_chars = "[-!#{$&}^_.+0-9a-zA-Z]{0,126}"
|
110
|
+
restricted_name = "#{restricted_name_first}#{restricted_name_chars}"
|
111
|
+
MEDIA_TYPE_RE = %r{(#{restricted_name})/(#{restricted_name})}.freeze
|
104
112
|
I18N_RE = /[^[:alnum:]]/.freeze
|
105
113
|
BINARY_ENCODINGS = %w[base64 8bit].freeze
|
106
114
|
ASCII_ENCODINGS = %w[7bit quoted-printable].freeze
|
@@ -110,12 +118,15 @@ class MIME::Type
|
|
110
118
|
:ASCII_ENCODINGS
|
111
119
|
|
112
120
|
# Builds a MIME::Type object from the +content_type+, a MIME Content Type
|
113
|
-
# value (e.g.,
|
121
|
+
# value (e.g., "text/plain" or "application/x-eruby"). The constructed object
|
114
122
|
# is yielded to an optional block for additional configuration, such as
|
115
123
|
# associating extensions and encoding information.
|
116
124
|
#
|
117
125
|
# * When provided a Hash or a MIME::Type, the MIME::Type will be
|
118
126
|
# constructed with #init_with.
|
127
|
+
#
|
128
|
+
# There are two deprecated initialization forms:
|
129
|
+
#
|
119
130
|
# * When provided an Array, the MIME::Type will be constructed using
|
120
131
|
# the first element as the content type and the remaining flattened
|
121
132
|
# elements as extensions.
|
@@ -132,11 +143,23 @@ class MIME::Type
|
|
132
143
|
when Hash
|
133
144
|
init_with(content_type)
|
134
145
|
when Array
|
146
|
+
MIME::Types.deprecated(
|
147
|
+
class: MIME::Type,
|
148
|
+
method: :new,
|
149
|
+
pre: "when called with an Array",
|
150
|
+
once: true
|
151
|
+
)
|
135
152
|
self.content_type = content_type.shift
|
136
153
|
self.extensions = content_type.flatten
|
137
154
|
when MIME::Type
|
138
155
|
init_with(content_type.to_h)
|
139
156
|
else
|
157
|
+
MIME::Types.deprecated(
|
158
|
+
class: MIME::Type,
|
159
|
+
method: :new,
|
160
|
+
pre: "when called with a String",
|
161
|
+
once: true
|
162
|
+
)
|
140
163
|
self.content_type = content_type
|
141
164
|
end
|
142
165
|
|
@@ -181,7 +204,7 @@ class MIME::Type
|
|
181
204
|
# comparisons involved are:
|
182
205
|
#
|
183
206
|
# 1. self.simplified <=> other.simplified (ensures that we
|
184
|
-
#
|
207
|
+
# do not try to compare different types)
|
185
208
|
# 2. IANA-registered definitions < other definitions.
|
186
209
|
# 3. Complete definitions < incomplete definitions.
|
187
210
|
# 4. Current definitions < obsolete definitions.
|
@@ -243,7 +266,7 @@ class MIME::Type
|
|
243
266
|
# +a.simplified+.
|
244
267
|
#
|
245
268
|
# Presumably, if <code>a.simplified <=> b.simplified</code> is +0+, then
|
246
|
-
# +a.simplified+ has the same hash as +b.simplified+. So we assume it
|
269
|
+
# +a.simplified+ has the same hash as +b.simplified+. So we assume it is
|
247
270
|
# suitable for #hash to delegate to #simplified in service of the #eql?
|
248
271
|
# invariant.
|
249
272
|
def hash
|
@@ -319,7 +342,7 @@ class MIME::Type
|
|
319
342
|
# exceptions defined, the first extension will be used.
|
320
343
|
#
|
321
344
|
# When setting #preferred_extensions, if #extensions does not contain this
|
322
|
-
# extension, this will be added to #
|
345
|
+
# extension, this will be added to #extensions.
|
323
346
|
#
|
324
347
|
# :attr_accessor: preferred_extension
|
325
348
|
|
@@ -330,7 +353,9 @@ class MIME::Type
|
|
330
353
|
|
331
354
|
##
|
332
355
|
def preferred_extension=(value) # :nodoc:
|
333
|
-
|
356
|
+
if value
|
357
|
+
add_extensions(value)
|
358
|
+
end
|
334
359
|
@preferred_extension = value
|
335
360
|
end
|
336
361
|
|
@@ -343,7 +368,7 @@ class MIME::Type
|
|
343
368
|
# provided is invalid.
|
344
369
|
#
|
345
370
|
# If the encoding is not provided on construction, this will be either
|
346
|
-
#
|
371
|
+
# "quoted-printable" (for text/* media types) and "base64" for eveything
|
347
372
|
# else.
|
348
373
|
#
|
349
374
|
# :attr_accessor: encoding
|
@@ -393,7 +418,7 @@ class MIME::Type
|
|
393
418
|
#
|
394
419
|
# call-seq:
|
395
420
|
# text_plain.friendly # => "Text File"
|
396
|
-
# text_plain.friendly(
|
421
|
+
# text_plain.friendly("en") # => "Text File"
|
397
422
|
def friendly(lang = "en")
|
398
423
|
@friendly ||= {}
|
399
424
|
|
@@ -486,7 +511,7 @@ class MIME::Type
|
|
486
511
|
# Returns the MIME::Type as a string for implicit conversions. This allows
|
487
512
|
# MIME::Type objects to appear on either side of a comparison.
|
488
513
|
#
|
489
|
-
#
|
514
|
+
# "text/plain" == MIME::Type.new("content-type" => "text/plain")
|
490
515
|
def to_str
|
491
516
|
content_type
|
492
517
|
end
|
@@ -627,7 +652,7 @@ class MIME::Type
|
|
627
652
|
-string
|
628
653
|
end
|
629
654
|
else
|
630
|
-
# MRI 2.2 and older
|
655
|
+
# MRI 2.2 and older do not have a method for string interning,
|
631
656
|
# so we simply freeze them for keeping a similar interface
|
632
657
|
def intern_string(string)
|
633
658
|
string.freeze
|
data/lib/mime/types/container.rb
CHANGED
@@ -5,10 +5,10 @@ require "forwardable"
|
|
5
5
|
|
6
6
|
# MIME::Types requires a serializable keyed container that returns an empty Set
|
7
7
|
# on a key miss. Hash#default_value cannot be used because, while it traverses
|
8
|
-
# the Marshal format correctly, it
|
8
|
+
# the Marshal format correctly, it will not survive any other serialization
|
9
9
|
# format (plus, a default of a mutable object resuls in a shared mess).
|
10
10
|
# Hash#default_proc cannot be used without a wrapper because it prevents
|
11
|
-
# Marshal serialization (and
|
11
|
+
# Marshal serialization (and does not survive the round-trip).
|
12
12
|
class MIME::Types::Container # :nodoc:
|
13
13
|
extend Forwardable
|
14
14
|
|
@@ -2,35 +2,55 @@
|
|
2
2
|
|
3
3
|
require "mime/types/logger"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
class << MIME::Types
|
6
|
+
# Used to mark a method as deprecated in the mime-types interface.
|
7
|
+
def deprecated(options = {}, &block) # :nodoc:
|
8
|
+
message =
|
9
|
+
if options[:message]
|
10
|
+
options[:message]
|
11
|
+
else
|
12
|
+
klass = options.fetch(:class)
|
13
|
+
|
14
|
+
msep = case klass
|
13
15
|
when Class, Module
|
14
16
|
"."
|
15
17
|
else
|
16
18
|
klass = klass.class
|
17
19
|
"#"
|
18
20
|
end
|
19
|
-
|
20
|
-
|
21
|
+
|
22
|
+
method = "#{klass}#{msep}#{options.fetch(:method)}"
|
23
|
+
pre = " #{options[:pre]}" if options[:pre]
|
24
|
+
post = case options[:next]
|
21
25
|
when :private, :protected
|
22
|
-
"and will be #{
|
23
|
-
when
|
24
|
-
"and will be removed"
|
26
|
+
" and will be made #{options[:next]}"
|
27
|
+
when :removed
|
28
|
+
" and will be removed"
|
29
|
+
when nil, ""
|
30
|
+
nil
|
25
31
|
else
|
26
|
-
|
32
|
+
" #{options[:next]}"
|
27
33
|
end
|
28
|
-
MIME::Types.logger.debug <<-WARNING.chomp.strip
|
29
|
-
#{caller(2..2).first}: #{klass}#{level}#{sym} is deprecated #{message}.
|
30
|
-
WARNING
|
31
34
|
|
32
|
-
|
33
|
-
|
35
|
+
<<-WARNING.chomp.strip
|
36
|
+
#{caller(2..2).first}: #{klass}#{msep}#{method}#{pre} is deprecated#{post}.
|
37
|
+
WARNING
|
38
|
+
end
|
39
|
+
|
40
|
+
if !__deprecation_logged?(message, options[:once])
|
41
|
+
MIME::Types.logger.__send__(options[:level] || :debug, message)
|
34
42
|
end
|
43
|
+
|
44
|
+
return unless block
|
45
|
+
block.call
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def __deprecation_logged?(message, once)
|
51
|
+
return false unless once
|
52
|
+
|
53
|
+
@__deprecations_logged = {} unless defined?(@__deprecations_logged)
|
54
|
+
@__deprecations_logged.key?(message)
|
35
55
|
end
|
36
56
|
end
|
data/lib/mime/types/loader.rb
CHANGED
@@ -13,7 +13,7 @@ require "mime/types/data"
|
|
13
13
|
#
|
14
14
|
# The Loader will use one of the following paths:
|
15
15
|
# 1. The +path+ provided in its constructor argument;
|
16
|
-
# 2. The value of ENV[
|
16
|
+
# 2. The value of ENV["RUBY_MIME_TYPES_DATA"]; or
|
17
17
|
# 3. The value of MIME::Types::Data::PATH.
|
18
18
|
#
|
19
19
|
# When #load is called, the +path+ will be searched recursively for all YAML
|
data/lib/mime/types/registry.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "mime/types/deprecations"
|
4
|
+
|
3
5
|
class << MIME::Types
|
4
6
|
include Enumerable
|
5
7
|
|
@@ -45,11 +47,11 @@ class << MIME::Types
|
|
45
47
|
def lazy_load?
|
46
48
|
return unless ENV.key?("RUBY_MIME_TYPES_LAZY_LOAD")
|
47
49
|
|
48
|
-
|
49
|
-
Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed.
|
50
|
-
|
50
|
+
deprecated(
|
51
|
+
message: "Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed."
|
52
|
+
)
|
51
53
|
|
52
|
-
|
54
|
+
ENV["RUBY_MIME_TYPES_LAZY_LOAD"] != "false"
|
53
55
|
end
|
54
56
|
|
55
57
|
def __types__
|
data/test/test_mime_type.rb
CHANGED
@@ -9,13 +9,13 @@ describe MIME::Type do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:x_appl_x_zip) {
|
12
|
-
mime_type("x-appl/x-zip") { |t| t.extensions = %w[zip zp] }
|
12
|
+
mime_type("content-type" => "x-appl/x-zip") { |t| t.extensions = %w[zip zp] }
|
13
13
|
}
|
14
|
-
let(:text_plain) { mime_type("text/plain") }
|
15
|
-
let(:text_html) { mime_type("text/html") }
|
16
|
-
let(:image_jpeg) { mime_type("image/jpeg") }
|
14
|
+
let(:text_plain) { mime_type("content-type" => "text/plain") }
|
15
|
+
let(:text_html) { mime_type("content-type" => "text/html") }
|
16
|
+
let(:image_jpeg) { mime_type("content-type" => "image/jpeg") }
|
17
17
|
let(:application_javascript) {
|
18
|
-
mime_type("application/javascript") do |js|
|
18
|
+
mime_type("content-type" => "application/javascript") do |js|
|
19
19
|
js.friendly("en" => "JavaScript")
|
20
20
|
js.xrefs = {
|
21
21
|
"rfc" => %w[rfc4239 rfc4239],
|
@@ -27,7 +27,7 @@ describe MIME::Type do
|
|
27
27
|
end
|
28
28
|
}
|
29
29
|
let(:text_x_yaml) {
|
30
|
-
mime_type("text/x-yaml") do |yaml|
|
30
|
+
mime_type("content-type" => "text/x-yaml") do |yaml|
|
31
31
|
yaml.extensions = %w[yaml yml]
|
32
32
|
yaml.encoding = "8bit"
|
33
33
|
yaml.friendly("en" => "YAML Structured Document")
|
@@ -88,20 +88,22 @@ describe MIME::Type do
|
|
88
88
|
describe ".new" do
|
89
89
|
it "fails if an invalid content type is provided" do
|
90
90
|
exception = assert_raises MIME::Type::InvalidContentType do
|
91
|
-
MIME::Type.new("apps")
|
91
|
+
MIME::Type.new("content-type" => "apps")
|
92
92
|
end
|
93
93
|
assert_equal 'Invalid Content-Type "apps"', exception.to_s
|
94
94
|
end
|
95
95
|
|
96
96
|
it "creates a valid content type just from a string" do
|
97
|
-
|
97
|
+
assert_output "", /MIME::Type.new when called with a String is deprecated\./ do
|
98
|
+
type = MIME::Type.new("text/x-yaml")
|
98
99
|
|
99
|
-
|
100
|
-
|
100
|
+
assert_instance_of MIME::Type, type
|
101
|
+
assert_equal "text/x-yaml", type.content_type
|
102
|
+
end
|
101
103
|
end
|
102
104
|
|
103
105
|
it "yields the content type in a block" do
|
104
|
-
MIME::Type.new("text/x-yaml") do |type|
|
106
|
+
MIME::Type.new("content-type" => "text/x-yaml") do |type|
|
105
107
|
assert_instance_of MIME::Type, type
|
106
108
|
assert_equal "text/x-yaml", type.content_type
|
107
109
|
end
|
@@ -118,10 +120,12 @@ describe MIME::Type do
|
|
118
120
|
end
|
119
121
|
|
120
122
|
it "creates a valid content type from an array" do
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
assert_output "", /MIME::Type.new when called with an Array is deprecated\./ do
|
124
|
+
type = MIME::Type.new(%w[text/x-yaml yaml yml yz])
|
125
|
+
assert_instance_of MIME::Type, type
|
126
|
+
assert_equal "text/x-yaml", type.content_type
|
127
|
+
assert_equal %w[yaml yml yz], type.extensions
|
128
|
+
end
|
125
129
|
end
|
126
130
|
end
|
127
131
|
|
@@ -143,7 +147,7 @@ describe MIME::Type do
|
|
143
147
|
end
|
144
148
|
|
145
149
|
it "correctly compares equivalent types" do
|
146
|
-
right = mime_type("text/Plain")
|
150
|
+
right = mime_type("content-type" => "text/Plain")
|
147
151
|
refute_same text_plain, right
|
148
152
|
assert_equal text_plain, right
|
149
153
|
end
|
@@ -204,14 +208,14 @@ describe MIME::Type do
|
|
204
208
|
end
|
205
209
|
|
206
210
|
it "is false when there are no extensions" do
|
207
|
-
refute mime_type("text/plain").complete?
|
211
|
+
refute mime_type("content-type" => "text/plain").complete?
|
208
212
|
end
|
209
213
|
end
|
210
214
|
|
211
215
|
describe "#content_type" do
|
212
216
|
it "preserves the original case" do
|
213
217
|
assert_equal "text/plain", text_plain.content_type
|
214
|
-
assert_equal "text/vCard", mime_type("text/vCard").content_type
|
218
|
+
assert_equal "text/vCard", mime_type("content-type" => "text/vCard").content_type
|
215
219
|
end
|
216
220
|
|
217
221
|
it "does not remove x- prefixes" do
|
@@ -266,27 +270,27 @@ describe MIME::Type do
|
|
266
270
|
end
|
267
271
|
|
268
272
|
it "is true for an equivalent MIME::Type" do
|
269
|
-
assert text_plain.eql?(mime_type("text/Plain"))
|
273
|
+
assert text_plain.eql?(mime_type("content-type" => "text/Plain"))
|
270
274
|
end
|
271
275
|
|
272
276
|
it "is true for an equivalent subclass of MIME::Type" do
|
273
277
|
subclass = Class.new(MIME::Type)
|
274
|
-
assert text_plain.eql?(subclass.new("text/plain"))
|
278
|
+
assert text_plain.eql?(subclass.new("content-type" => "text/plain"))
|
275
279
|
end
|
276
280
|
end
|
277
281
|
|
278
282
|
describe "#hash" do
|
279
283
|
it "is the same between #eql? MIME::Type instances" do
|
280
|
-
assert_equal text_plain.hash, mime_type("text/plain").hash
|
284
|
+
assert_equal text_plain.hash, mime_type("content-type" => "text/plain").hash
|
281
285
|
end
|
282
286
|
|
283
287
|
it "is the same between #eql? MIME::Type instances of different classes" do
|
284
288
|
subclass = Class.new(MIME::Type)
|
285
|
-
assert_equal text_plain.hash, subclass.new("text/plain").hash
|
289
|
+
assert_equal text_plain.hash, subclass.new("content-type" => "text/plain").hash
|
286
290
|
end
|
287
291
|
|
288
292
|
it "uses the #simplified value" do
|
289
|
-
assert_equal text_plain.hash, mime_type("text/Plain").hash
|
293
|
+
assert_equal text_plain.hash, mime_type("content-type" => "text/Plain").hash
|
290
294
|
end
|
291
295
|
end
|
292
296
|
|
@@ -340,9 +344,9 @@ describe MIME::Type do
|
|
340
344
|
assert_priority_more right, left
|
341
345
|
end
|
342
346
|
|
343
|
-
let(:text_1) { mime_type("text/1") }
|
344
|
-
let(:text_1p) { mime_type("text/1") }
|
345
|
-
let(:text_2) { mime_type("text/2") }
|
347
|
+
let(:text_1) { mime_type("content-type" => "text/1") }
|
348
|
+
let(:text_1p) { mime_type("content-type" => "text/1") }
|
349
|
+
let(:text_2) { mime_type("content-type" => "text/2") }
|
346
350
|
|
347
351
|
it "sorts (1) based on the simplified type" do
|
348
352
|
assert_priority text_1, text_1p, text_2
|
@@ -395,7 +399,7 @@ describe MIME::Type do
|
|
395
399
|
|
396
400
|
describe "#raw_media_type" do
|
397
401
|
it "extracts the media type as case-preserved" do
|
398
|
-
assert_equal "Text", mime_type("Text/plain").raw_media_type
|
402
|
+
assert_equal "Text", mime_type("content-type" => "Text/plain").raw_media_type
|
399
403
|
end
|
400
404
|
|
401
405
|
it "does not remove x- prefixes" do
|
@@ -415,7 +419,7 @@ describe MIME::Type do
|
|
415
419
|
|
416
420
|
describe "#raw_media_type" do
|
417
421
|
it "extracts the media type as case-preserved" do
|
418
|
-
assert_equal "Text", mime_type("Text/plain").raw_media_type
|
422
|
+
assert_equal "Text", mime_type("content-type" => "Text/plain").raw_media_type
|
419
423
|
end
|
420
424
|
|
421
425
|
it "does not remove x- prefixes" do
|
@@ -435,7 +439,7 @@ describe MIME::Type do
|
|
435
439
|
|
436
440
|
describe "#raw_sub_type" do
|
437
441
|
it "extracts the sub type as case-preserved" do
|
438
|
-
assert_equal "Plain", mime_type("text/Plain").raw_sub_type
|
442
|
+
assert_equal "Plain", mime_type("content-type" => "text/Plain").raw_sub_type
|
439
443
|
end
|
440
444
|
|
441
445
|
it "does not remove x- prefixes" do
|
@@ -444,7 +448,7 @@ describe MIME::Type do
|
|
444
448
|
end
|
445
449
|
|
446
450
|
describe "#to_h" do
|
447
|
-
let(:t) { mime_type("a/b") }
|
451
|
+
let(:t) { mime_type("content-type" => "a/b") }
|
448
452
|
|
449
453
|
def assert_has_keys(wanted_keys, actual, msg = nil)
|
450
454
|
wanted_keys = Array(wanted_keys).uniq.sort
|
@@ -505,11 +509,11 @@ describe MIME::Type do
|
|
505
509
|
}
|
506
510
|
|
507
511
|
it "converts to JSON when requested" do
|
508
|
-
assert_equal expected_1, mime_type("a/b").to_json
|
512
|
+
assert_equal expected_1, mime_type("content-type" => "a/b").to_json
|
509
513
|
end
|
510
514
|
|
511
515
|
it "converts to JSON with provisional when requested" do
|
512
|
-
type = mime_type("a/b") do |t|
|
516
|
+
type = mime_type("content-type" => "a/b") do |t|
|
513
517
|
t.registered = true
|
514
518
|
t.provisional = true
|
515
519
|
end
|
@@ -559,7 +563,7 @@ describe MIME::Type do
|
|
559
563
|
}
|
560
564
|
|
561
565
|
let(:type) {
|
562
|
-
mime_type("a/b").tap do |t|
|
566
|
+
mime_type("content-type" => "a/b").tap do |t|
|
563
567
|
t.xrefs = {
|
564
568
|
"draft" => ["RFC1"],
|
565
569
|
"template" => ["a/b"],
|
data/test/test_mime_types.rb
CHANGED
@@ -6,19 +6,14 @@ require "minitest_helper"
|
|
6
6
|
describe MIME::Types do
|
7
7
|
def mime_types
|
8
8
|
@mime_types ||= MIME::Types.new.tap { |mt|
|
9
|
-
mt.add
|
10
|
-
MIME::Type.new(
|
11
|
-
MIME::Type.new("
|
12
|
-
MIME::Type.new(
|
13
|
-
|
14
|
-
|
15
|
-
)
|
16
|
-
|
17
|
-
MIME::Type.new(
|
18
|
-
"content-type" => "application/gzip",
|
19
|
-
"extensions" => "gz",
|
20
|
-
"registered" => true
|
21
|
-
)
|
9
|
+
mt.add(
|
10
|
+
MIME::Type.new("content-type" => "text/plain", "extensions" => %w[txt]),
|
11
|
+
MIME::Type.new("content-type" => "image/jpeg", "extensions" => %w[jpg jpeg]),
|
12
|
+
MIME::Type.new("content-type" => "application/x-wordperfect6.1"),
|
13
|
+
MIME::Type.new("content-type" => "application/x-www-form-urlencoded", "registered" => true),
|
14
|
+
MIME::Type.new("content-type" => "application/x-gzip", "extensions" => %w[gz]),
|
15
|
+
MIME::Type.new("content-type" => "application/gzip", "extensions" => "gz", "registered" => true)
|
16
|
+
)
|
22
17
|
}
|
23
18
|
end
|
24
19
|
|
@@ -45,7 +40,7 @@ describe MIME::Types do
|
|
45
40
|
|
46
41
|
describe "#[]" do
|
47
42
|
it "can be searched with a MIME::Type" do
|
48
|
-
text_plain = MIME::Type.new("text/plain")
|
43
|
+
text_plain = MIME::Type.new("content-type" => "text/plain")
|
49
44
|
assert_includes mime_types[text_plain], "text/plain"
|
50
45
|
assert_equal 1, mime_types[text_plain].size
|
51
46
|
end
|
@@ -92,8 +87,8 @@ describe MIME::Types do
|
|
92
87
|
end
|
93
88
|
|
94
89
|
describe "#add" do
|
95
|
-
let(:eruby) { MIME::Type.new("application/x-eruby") }
|
96
|
-
let(:jinja) { MIME::Type.new("application/jinja2") }
|
90
|
+
let(:eruby) { MIME::Type.new("content-type" => "application/x-eruby") }
|
91
|
+
let(:jinja) { MIME::Type.new("content-type" => "application/jinja2") }
|
97
92
|
|
98
93
|
it "successfully adds a new type" do
|
99
94
|
mime_types.add(eruby)
|
@@ -31,7 +31,7 @@ describe MIME::Types, "registry" do
|
|
31
31
|
|
32
32
|
describe ".[]" do
|
33
33
|
it "can be searched with a MIME::Type" do
|
34
|
-
text_plain = MIME::Type.new("text/plain")
|
34
|
+
text_plain = MIME::Type.new("content-type" => "text/plain")
|
35
35
|
assert_includes MIME::Types[text_plain], "text/plain"
|
36
36
|
assert_equal 1, MIME::Types[text_plain].size
|
37
37
|
end
|
@@ -119,8 +119,8 @@ describe MIME::Types, "registry" do
|
|
119
119
|
MIME::Types.send(:load_default_mime_types)
|
120
120
|
end
|
121
121
|
|
122
|
-
let(:eruby) { MIME::Type.new("application/x-eruby") }
|
123
|
-
let(:jinja) { MIME::Type.new("application/jinja2") }
|
122
|
+
let(:eruby) { MIME::Type.new("content-type" => "application/x-eruby") }
|
123
|
+
let(:jinja) { MIME::Type.new("content-type" => "application/jinja2") }
|
124
124
|
|
125
125
|
it "successfully adds a new type" do
|
126
126
|
MIME::Types.add(eruby)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mime-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Ziegler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types-data
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2015'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: logger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '5.
|
47
|
+
version: '5.25'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '5.
|
54
|
+
version: '5.25'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: hoe
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -307,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
307
321
|
- !ruby/object:Gem::Version
|
308
322
|
version: '0'
|
309
323
|
requirements: []
|
310
|
-
rubygems_version: 3.5.
|
324
|
+
rubygems_version: 3.5.16
|
311
325
|
signing_key:
|
312
326
|
specification_version: 4
|
313
327
|
summary: The mime-types library provides a library and registry for information about
|