mime-types 3.4.1 → 3.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 443bfcc0047c25a8ac7cc9e7a2fea95f8d4707e8fa3a98d0b99bee421e168708
4
- data.tar.gz: 39756d60550165df9787a4967c376faac32179fd442d176766893b7454ed977d
3
+ metadata.gz: cfc8b8464d84ae454c33d168638a3c496d4a7c9bcdcc5fb76905a4db3f7f8c68
4
+ data.tar.gz: 90b122e2a9fb78b41e350f92038854491bf95520cd6764e7719a086da3afa5ff
5
5
  SHA512:
6
- metadata.gz: d711882ac22adb5a8ab3e4953a508c06e870990ad0d41d0256679bcb66c7953686ba4b23ac1470ea6ee07d6026d793f57fb7d377d321fb972252365c8fd22622
7
- data.tar.gz: 3d20e16be727ee9b62ab599a939524148577b54281a63705b0b75a9eea7c6f51df169bc6979ce8b616c3b707921c1021ac06b226bb8df28f5337d1f76107a293
6
+ metadata.gz: '068f424c28bda754c9870faf925a80525721e7baff71b582ad9b91041510f078c6dc1d1316362347a406dd31c6843c28abd05fdcf7ec211ce35e617817f3741b'
7
+ data.tar.gz: 7d47eb015acfb84adc666c2ba59eb38da6d349bb029d407725f1046b2ec375a61aee3fcf195bd92f663400a9c9e14ca9d3c53022ad4ba9049b2ef46e662b65ab
data/.standard.yml ADDED
@@ -0,0 +1,4 @@
1
+ parallel: true
2
+ ruby_version: 2.3
3
+ ignore:
4
+ - 'mime-types.gemspec'
data/Contributing.md CHANGED
@@ -6,11 +6,11 @@ request, or code contributions.
6
6
  There are a few guidelines for contributing to mime-types:
7
7
 
8
8
  - Code changes _will_ _not_ be accepted without tests. The test suite is
9
- written with [minitest].
9
+ written with [minitest][].
10
10
  - Match my coding style.
11
11
  - Use a thoughtfully-named topic branch that contains your change. Rebase your
12
12
  commits into logical chunks as necessary.
13
- - Use [quality commit messages].
13
+ - Use [quality commit messages][].
14
14
  - Do not change the version number; when your patch is accepted and a release
15
15
  is made, the version will be updated at that point.
16
16
  - Submit a GitHub pull request with your changes.
@@ -19,25 +19,23 @@ There are a few guidelines for contributing to mime-types:
19
19
  ## Adding or Modifying MIME Types
20
20
 
21
21
  The mime-types registry is no longer contained in mime-types, but in
22
- [mime-types-data]. Please see that project for contributions there.
22
+ [mime-types-data][]. Please see that project for contributions there.
23
23
 
24
24
  ### Test Dependencies
25
25
 
26
- mime-types uses Ryan Davis’s [Hoe] to manage the release process, and it adds
27
- a number of rake tasks. You will mostly be interested in `rake`, which runs
28
- the tests the same way that `rake test` or `rake travis` will do.
26
+ mime-types uses Ryan Davis’s [Hoe][] to manage the release process, and it adds
27
+ a number of rake tasks. You will mostly be interested in `rake`, which runs the
28
+ tests the same way that `rake test` will do.
29
29
 
30
30
  To assist with the installation of the development dependencies for
31
31
  mime-types, I have provided the simplest possible Gemfile pointing to the
32
- (generated) `mime-types.gemspec` file. This will permit you to do `bundle
33
- install` to get the development dependencies. If you aleady have `hoe`
32
+ (generated) `mime-types.gemspec` file. This will permit you to do `bundle install` to get the development dependencies. If you already have `hoe`
34
33
  installed, you can accomplish the same thing with `rake newb`.
35
34
 
36
35
  This task will install any missing dependencies, run the tests/specs, and
37
36
  generate the RDoc.
38
37
 
39
- You can run tests with code coverage analysis by running `rake
40
- test:coverage`.
38
+ You can run tests with code coverage analysis by running `rake test:coverage`.
41
39
 
42
40
  ## Benchmarks
43
41
 
@@ -52,7 +50,7 @@ built-in benchmark library:
52
50
 
53
51
  There are two allocation tracing benchmarks (for normal and columnar loads).
54
52
  These can only be run on Ruby 2.1 or better and requires the
55
- [allocation\_tracer] gem (not installed by default).
53
+ [allocation\_tracer][] gem (not installed by default).
56
54
 
57
55
  - `rake benchmark:allocations`
58
56
  - `rake benchmark:allocations:columnar`
@@ -86,6 +84,7 @@ Thanks to everyone else who has contributed to mime-types over the years:
86
84
  - Aaron Patterson
87
85
  - Aggelos Avgerinos
88
86
  - Al Snow
87
+ - Alex Vondrak
89
88
  - Andre Pankratz
90
89
  - Andy Brody
91
90
  - Arnaud Meuret
@@ -94,8 +93,8 @@ Thanks to everyone else who has contributed to mime-types over the years:
94
93
  - Chris Gat
95
94
  - David Genord
96
95
  - Dillon Welch
97
- - Eric Marden
98
96
  - Edward Betts
97
+ - Eric Marden
99
98
  - Garret Alfert
100
99
  - Godfrey Chan
101
100
  - Greg Brockman
@@ -107,21 +106,23 @@ Thanks to everyone else who has contributed to mime-types over the years:
107
106
  - Jeremy Evans
108
107
  - Juanito Fatas
109
108
  - Jun Aruga
110
- - Łukasz Śliwa
111
109
  - Keerthi Siva
112
110
  - Ken Ip
113
111
  - Kevin Menard
114
112
  - Koichi ITO
113
+ - Łukasz Śliwa
115
114
  - Martin d'Allens
115
+ - Masato Nakamura
116
116
  - Mauricio Linhares
117
- - Nicolas Leger
118
117
  - Nicholas La Roux
118
+ - Nicolas Leger
119
119
  - nycvotes-dev
120
120
  - Olle Jonsson
121
121
  - Postmodern
122
122
  - Richard Hirner
123
123
  - Richard Hurt
124
124
  - Richard Schneeman
125
+ - Robb Shecter
125
126
  - Tibor Szolár
126
127
  - Todd Carrico
127
128
 
data/History.md CHANGED
@@ -1,8 +1,65 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.5.2 / 2024-01-02
4
+
5
+ There are no primary code changes, but we are releasing this as an update as
6
+ there are some validation changes and updated code with formatting.
7
+
8
+ - Dependency and CI updates:
9
+
10
+ - Masato Nakamura added Ruby 3.3 to the CI workflow in [#179][].
11
+
12
+ - Fixed regressions in standard formatting in [#180][].
13
+
14
+ - Removed `minitest-bonus-assertions` because of a bundler resolution issue.
15
+ Created a better replacement in-line.
16
+
17
+ ## 3.5.1 / 2023-08-21
18
+
19
+ - 1 bug fix:
20
+
21
+ - Better handle possible line-termination strings (legal in Unix filenames)
22
+ such as `\n` in `MIME::Types.type_for`. Reported by ooooooo-q in [#177][],
23
+ resolved in [#178][].
24
+
25
+ ## 3.5.0 / 2023-08-07
26
+
27
+ - 1 minor enhancement:
28
+
29
+ - Robb Shecter changed the default log level for duplicate type variant from
30
+ `warn` to `debug` in [#170][]. This works because `MIME::Types.logger` is
31
+ intended to fit the `::Logger` interface, and the default logger
32
+ (`WarnLogger`) is a subclass of `::Logger` that passes through to
33
+ `Kernel.warn`.
34
+
35
+ - Further consideration has changed cache load messages from `warn` to
36
+ `error` and deprecation messages from `warn` to `debug`.
37
+
38
+ - 1 bug fix:
39
+
40
+ - Added a definition of `MIME::Type#hash`. Contributed by Alex Vondrak in
41
+ [#167][], fixing [#166][].
42
+
43
+ - Dependency and CI updates:
44
+
45
+ - Update the .github/workflows/ci.yml workflow to test Ruby 3.2 and more
46
+ reliably test certain combinations rather than depending on exclusions.
47
+
48
+ - Change `.standard.yml` configuration to format for Ruby 2.3 as certain files
49
+ are not properly detected with Ruby 2.0.
50
+
51
+ - Change from `hoe-git` to `hoe-git2` to support Hoe version 4.
52
+
53
+ - Apply `standardrb --fix`.
54
+
55
+ - The above changes have resulted in the Soft deprecation of Ruby versions
56
+ below 2.6. Any errors reported for Ruby versions 2.0, 2.1, 2.2, 2.3, 2.4,
57
+ and 2.5 will be resolved, but maintaining CI for these versions is
58
+ unsustainable.
59
+
3
60
  ## 3.4.1 / 2021-11-16
4
61
 
5
- - 1 bugfix:
62
+ - 1 bug fix:
6
63
 
7
64
  - Fixed a Ruby < 2.3 incompatibility introduced by the use of standardrb,
8
65
  where `<<-` heredocs were converted to `<<~` heredocs. These have been
@@ -26,7 +83,7 @@
26
83
  - Added Ruby 3.0 to the CI test matrix. Added `windows/jruby` to the
27
84
  CI exclusion list; it refuses to run successfully.
28
85
  - Removed the Travis CI configuration and changed it to Github Workflows
29
- [#150]. Removed Coveralls configuration.
86
+ [#150][]. Removed Coveralls configuration.
30
87
  - Igor Victor added TruffleRuby to the Travis CI configuration. [#149]
31
88
  - Koichi ITO loosened an excessively tight dependency. [#147]
32
89
  - Started using `standardrb` for Ruby formatting and validation.
@@ -34,7 +91,7 @@
34
91
 
35
92
  ## 3.3.1 / 2019-12-26
36
93
 
37
- - 1 minor bugfix:
94
+ - 1 minor bug fix:
38
95
 
39
96
  - Al Snow fixed a warning with MIME::Types::Logger producing a warning
40
97
  because Ruby 2.7 introduces numbered block parameters. Because of the way
@@ -44,7 +101,7 @@
44
101
 
45
102
  - Administrivia:
46
103
 
47
- - Olle Jonsson removed an outdated Travis configuration option (`sudo: false`). [#142]
104
+ - Olle Jonsson removed an outdated Travis configuration option. [#142][]
48
105
 
49
106
  ## 3.3 / 2019-09-04
50
107
 
@@ -79,8 +136,9 @@
79
136
  to be in the same family even if strict sorting would cause an
80
137
  unregistered type to be sorted first. [#132]
81
138
 
82
- - Dillon Welch contributed a change that added `frozen_string_literal: true` to files so that modern Rubies can automatically reduce duplicate
83
- string allocations. [#135]
139
+ - Dillon Welch contributed a change that added `frozen_string_literal: true`
140
+ to files so that modern Rubies can automatically reduce duplicate string
141
+ allocations. [#135]
84
142
 
85
143
  - 2 bug fixes
86
144
 
@@ -91,7 +149,7 @@
91
149
  because when Enumerable#inject isn't provided a starting value, the first
92
150
  value is used as the default value. In every case where this error was
93
151
  happening, the result was supposed to be an array containing Set objects
94
- so they can be reduced to a single Set. [#117], [#127], [#134]
152
+ so they can be reduced to a single Set. [#117][], [#127][], [#134][]
95
153
 
96
154
  - Fixed an uncontrolled growth bug in MIME::Types::Container where a key
97
155
  miss would create a new entry with an empty Set in the container. This
@@ -113,12 +171,12 @@
113
171
  - The history file has been modified to remove all history prior to 3.0.
114
172
  This history can be found in previous commits.
115
173
 
116
- - A spelling error was corrected by Edward Betts ([#129]).
174
+ - A spelling error was corrected by Edward Betts ([#129][]).
117
175
 
118
176
  - Administrivia:
119
177
 
120
178
  - CI configuration for more modern versions of Ruby were added by Nicolas
121
- Leger ([#130]), Jun Aruga ([#125]), and Austin Ziegler. Removed
179
+ Leger ([#130][]), Jun Aruga ([#125][]), and Austin Ziegler. Removed
122
180
  ruby-head-clang and rbx (Rubinius) from CI.
123
181
 
124
182
  - Fixed tests which were asserting equality against nil, which will become
@@ -129,18 +187,18 @@
129
187
  - 1 documentation change:
130
188
 
131
189
  - Tim Smith (@tas50) updated the build badges to be SVGs to improve
132
- readability on high-density (retina) screens with pull request [#112].
190
+ readability on high-density (retina) screens with pull request [#112][].
133
191
 
134
192
  - 3 bug fixes
135
193
 
136
194
  - A test for `MIME::Types::Cache` fails under Ruby 2.3 because of frozen
137
- strings, [#118]. This has been fixed.
195
+ strings, [#118][]. This has been fixed.
138
196
 
139
197
  - The JSON data has been incorrectly encoded since the release of
140
198
  mime-types 3 on the `xrefs` field, because of the switch to using a Set
141
199
  to store cross-reference information. This has been fixed.
142
200
 
143
- - A tentative fix for [#117] has been applied, removing the only circular
201
+ - A tentative fix for [#117][] has been applied, removing the only circular
144
202
  require dependencies that exist (and for which there was code to prevent,
145
203
  but the current fix is simpler). I have no way to verify this fix and
146
204
  depending on how things are loaded by `delayed_job`, this fix may not be
@@ -155,22 +213,22 @@
155
213
  - 2 governance changes
156
214
 
157
215
  - This project and the related mime-types-data project are now exclusively
158
- MIT licensed. Resolves [#95].
216
+ MIT licensed. Resolves [#95][].
159
217
 
160
218
  - All projects under the mime-types organization now have a standard code
161
- of conduct adapted from the [Contributor Covenant]. This text can be
162
- found in the [Code-of-Conduct.md] file.
219
+ of conduct adapted from the [Contributor Covenant][]. This text can be
220
+ found in the [Code-of-Conduct.md][] file.
163
221
 
164
222
  - 3 major changes
165
223
 
166
224
  - All methods deprecated in mime-types 2.x have been removed.
167
225
 
168
226
  - mime-types now requires Ruby 2.0 compatibility or later. Resolves
169
- [#97].
227
+ [#97][].
170
228
 
171
229
  - The registry data has been removed from mime-types and put into
172
230
  mime-types-data, maintained and released separately. It can be found at
173
- [mime-types-data].
231
+ [mime-types-data][].
174
232
 
175
233
  - 17 minor changes:
176
234
 
@@ -183,8 +241,9 @@
183
241
  `x-` prefixes.
184
242
 
185
243
  - Improved initialization with an Array works so that extensions do not
186
- need to be wrapped in another array. This means that `%w(text/yaml yaml yml)` works in the same way that `['text/yaml', %w(yaml yml)]` did (and
187
- still does).
244
+ need to be wrapped in another array. This means that
245
+ `%w(text/yaml yaml yml)` works in the same way that
246
+ `['text/yaml', %w(yaml yml)]` did (and still does).
188
247
 
189
248
  - Changed `priority_compare` to conform with attributes that no longer
190
249
  exist.
@@ -192,8 +251,8 @@
192
251
  - Changed the internal implementation of extensions to use a frozen Set.
193
252
 
194
253
  - When extensions are set or modified with `add_extensions`, the primary
195
- registry will be informed of a need to reindex extensions. Resolves
196
- [#84].
254
+ registry will be informed of a need to re-index extensions. Resolves
255
+ [#84][].
197
256
 
198
257
  - The preferred extension can be set explicitly. If not set, it will be
199
258
  the first extension. If the preferred extension is not in the extension
@@ -216,7 +275,7 @@
216
275
  - Extracted the class methods to a separate file.
217
276
 
218
277
  - Changed the container implementation to use a Set instead of an Array
219
- to prevent data duplication. Resolves [#79].
278
+ to prevent data duplication. Resolves [#79][].
220
279
 
221
280
  - `MIME::Types::Cache` changes:
222
281
 
@@ -235,7 +294,7 @@
235
294
 
236
295
  - The registry is default loaded from the columnar store by default. The
237
296
  internal format of the columnar store has changed; many of the boolean
238
- flags are now loaded from a single file. Resolves [#85].
297
+ flags are now loaded from a single file. Resolves [#85][].
239
298
 
240
299
  [#79]: https://github.com/mime-types/ruby-mime-types/pull/79
241
300
  [#84]: https://github.com/mime-types/ruby-mime-types/pull/84
@@ -264,6 +323,13 @@
264
323
  [#149]: https://github.com/mime-types/ruby-mime-types/pull/149
265
324
  [#150]: https://github.com/mime-types/ruby-mime-types/pull/150
266
325
  [#153]: https://github.com/mime-types/ruby-mime-types/pull/153
326
+ [#166]: https://github.com/mime-types/ruby-mime-types/issues/166
327
+ [#167]: https://github.com/mime-types/ruby-mime-types/pull/167
328
+ [#170]: https://github.com/mime-types/ruby-mime-types/pull/170
329
+ [#177]: https://github.com/mime-types/ruby-mime-types/issues/177
330
+ [#178]: https://github.com/mime-types/ruby-mime-types/pull/178
331
+ [#179]: https://github.com/mime-types/ruby-mime-types/pull/179
332
+ [#180]: https://github.com/mime-types/ruby-mime-types/pull/180
267
333
  [code-of-conduct.md]: Code-of-Conduct_md.html
268
334
  [contributor covenant]: http://contributor-covenant.org
269
335
  [mime-types-data]: https://github.com/mime-types/mime-types-data
data/Manifest.txt CHANGED
@@ -1,3 +1,4 @@
1
+ .standard.yml
1
2
  Code-of-Conduct.md
2
3
  Contributing.md
3
4
  History.md
data/README.rdoc CHANGED
@@ -5,7 +5,7 @@ code :: https://github.com/mime-types/ruby-mime-types/
5
5
  bugs :: https://github.com/mime-types/ruby-mime-types/issues
6
6
  rdoc :: http://rdoc.info/gems/mime-types/
7
7
  clog :: https://github.com/mime-types/ruby-mime-types/blob/master/History.md
8
- continuous integration :: {<img src="https://travis-ci.org/mime-types/ruby-mime-types.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/mime-types/ruby-mime-types]
8
+ continuous integration :: {<img src="https://github.com/mime-types/ruby-mime-types/actions/workflows/ci.yml/badge.svg" alt="Build Status" />}[https://github.com/mime-types/ruby-mime-types/actions/workflows/ci.yml]
9
9
  test coverage :: {<img src="https://coveralls.io/repos/mime-types/ruby-mime-types/badge.svg?branch=master&service=github" alt="Coverage Status" />}[https://coveralls.io/github/mime-types/ruby-mime-types?branch=master]
10
10
 
11
11
  == Description
data/Rakefile CHANGED
@@ -1,78 +1,39 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "rubygems"
4
2
  require "hoe"
5
3
  require "rake/clean"
6
4
 
7
- # This is required until https://github.com/seattlerb/hoe/issues/112 is fixed
8
- class Hoe
9
- def with_config
10
- config = Hoe::DEFAULT_CONFIG
11
-
12
- rc = File.expand_path("~/.hoerc")
13
- homeconfig = load_config(rc)
14
- config = config.merge(homeconfig)
15
-
16
- localconfig = load_config(File.expand_path(File.join(Dir.pwd, ".hoerc")))
17
- config = config.merge(localconfig)
18
-
19
- yield config, rc
20
- end
21
-
22
- def load_config(name)
23
- File.exist?(name) ? safe_load_yaml(name) : {}
24
- end
25
-
26
- def safe_load_yaml(name)
27
- return safe_load_yaml_file(name) if YAML.respond_to?(:safe_load_file)
28
-
29
- data = IO.binread(name)
30
- YAML.safe_load(data, permitted_classes: [Regexp])
31
- rescue
32
- YAML.safe_load(data, [Regexp])
33
- end
34
-
35
- def safe_load_yaml_file(name)
36
- YAML.safe_load_file(name, permitted_classes: [Regexp])
37
- rescue
38
- YAML.safe_load_file(name, [Regexp])
39
- end
40
- end
41
-
5
+ Hoe.plugin :cov
42
6
  Hoe.plugin :doofus
43
7
  Hoe.plugin :gemspec2
44
- Hoe.plugin :git
8
+ Hoe.plugin :git2
45
9
  Hoe.plugin :minitest
46
- Hoe.plugin :email unless ENV["CI"]
10
+ Hoe.plugin :rubygems
47
11
 
48
12
  spec = Hoe.spec "mime-types" do
49
13
  developer("Austin Ziegler", "halostatue@gmail.com")
50
- self.need_tar = true
51
-
52
- require_ruby_version ">= 2.0"
53
14
 
54
15
  self.history_file = "History.md"
55
16
  self.readme_file = "README.rdoc"
56
17
 
57
18
  license "MIT"
58
19
 
20
+ require_ruby_version ">= 2.0"
21
+
22
+ spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" }
23
+
59
24
  extra_deps << ["mime-types-data", "~> 3.2015"]
60
25
 
26
+ extra_dev_deps << ["hoe", ">= 3.0", "< 5"]
61
27
  extra_dev_deps << ["hoe-doofus", "~> 1.0"]
62
28
  extra_dev_deps << ["hoe-gemspec2", "~> 1.1"]
63
- extra_dev_deps << ["hoe-git", "~> 1.6"]
29
+ extra_dev_deps << ["hoe-git2", "~> 1.7"]
64
30
  extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
65
- extra_dev_deps << ["standard", "~> 1.0"]
66
- extra_dev_deps << ["minitest", "~> 5.4"]
31
+ extra_dev_deps << ["minitest", "~> 5.0"]
67
32
  extra_dev_deps << ["minitest-autotest", "~> 1.0"]
68
33
  extra_dev_deps << ["minitest-focus", "~> 1.0"]
69
- extra_dev_deps << ["minitest-bonus-assertions", "~> 3.0"]
70
34
  extra_dev_deps << ["minitest-hooks", "~> 1.4"]
71
35
  extra_dev_deps << ["rake", ">= 10.0", "< 14.0"]
72
-
73
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.0")
74
- extra_dev_deps << ["simplecov", "~> 0.7"]
75
- end
36
+ extra_dev_deps << ["standard", "~> 1.0"]
76
37
  end
77
38
 
78
39
  namespace :benchmark do
@@ -235,9 +196,7 @@ namespace :convert do
235
196
 
236
197
  file mark => [rdoc, :setup] do |t|
237
198
  puts "#{rdoc} => #{mark}"
238
- File.open(t.name, "wb") { |target|
239
- target.write @doc_converter.convert(IO.read(t.prerequisites.first))
240
- }
199
+ File.binwrite(t.name, @doc_converter.convert(IO.read(t.prerequisites.first)))
241
200
  end
242
201
 
243
202
  CLEAN.add mark
data/lib/mime/type.rb CHANGED
@@ -93,7 +93,7 @@ class MIME::Type
93
93
  end
94
94
 
95
95
  # The released version of the mime-types library.
96
- VERSION = "3.4.1"
96
+ VERSION = "3.5.2"
97
97
 
98
98
  include Comparable
99
99
 
@@ -224,6 +224,32 @@ class MIME::Type
224
224
  other.is_a?(MIME::Type) && (self == other)
225
225
  end
226
226
 
227
+ # Returns a hash based on the #simplified value.
228
+ #
229
+ # This maintains the invariant that two #eql? instances must have the same
230
+ # #hash (although having the same #hash does *not* imply that the objects are
231
+ # #eql?).
232
+ #
233
+ # To see why, suppose a MIME::Type instance +a+ is compared to another object
234
+ # +b+, and that <code>a.eql?(b)</code> is true. By the definition of #eql?,
235
+ # we know the following:
236
+ #
237
+ # 1. +b+ is a MIME::Type instance itself.
238
+ # 2. <code>a == b</code> is true.
239
+ #
240
+ # Due to the first point, we know that +b+ should respond to the #simplified
241
+ # method. Thus, per the definition of #<=>, we know that +a.simplified+ must
242
+ # be equal to +b.simplified+, as compared by the <=> method corresponding to
243
+ # +a.simplified+.
244
+ #
245
+ # 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's
247
+ # suitable for #hash to delegate to #simplified in service of the #eql?
248
+ # invariant.
249
+ def hash
250
+ simplified.hash
251
+ end
252
+
227
253
  # Returns the whole MIME content-type string.
228
254
  #
229
255
  # The content type is a presentation value from the MIME type registry and
@@ -338,7 +364,7 @@ class MIME::Type
338
364
 
339
365
  # Returns the default encoding for the MIME::Type based on the media type.
340
366
  def default_encoding
341
- @media_type == "text" ? "quoted-printable" : "base64"
367
+ (@media_type == "text") ? "quoted-printable" : "base64"
342
368
  end
343
369
 
344
370
  ##
@@ -22,13 +22,13 @@ class << MIME::Types::Cache
22
22
  if cache.version == MIME::Types::Data::VERSION
23
23
  Marshal.load(cache.data)
24
24
  else
25
- MIME::Types.logger.warn <<-WARNING.chomp.strip
25
+ MIME::Types.logger.error <<-WARNING.chomp.strip
26
26
  Could not load MIME::Types cache: invalid version
27
27
  WARNING
28
28
  nil
29
29
  end
30
30
  rescue => e
31
- MIME::Types.logger.warn <<-WARNING.chomp.strip
31
+ MIME::Types.logger.error <<-WARNING.chomp.strip
32
32
  Could not load MIME::Types cache: #{e}
33
33
  WARNING
34
34
  nil
@@ -49,10 +49,6 @@ class << MIME::Types::Cache
49
49
 
50
50
  types ||= MIME::Types.send(:__types__)
51
51
 
52
- File.open(cache_file, "wb") do |f|
53
- f.write(
54
- Marshal.dump(new(MIME::Types::Data::VERSION, Marshal.dump(types)))
55
- )
56
- end
52
+ File.binwrite(cache_file, Marshal.dump(new(MIME::Types::Data::VERSION, Marshal.dump(types))))
57
53
  end
58
54
  end
@@ -10,22 +10,22 @@ module MIME
10
10
  def self.deprecated(klass, sym, message = nil, &block) # :nodoc:
11
11
  level =
12
12
  case klass
13
- when Class, Module
14
- "."
15
- else
16
- klass = klass.class
17
- "#"
13
+ when Class, Module
14
+ "."
15
+ else
16
+ klass = klass.class
17
+ "#"
18
18
  end
19
19
  message =
20
20
  case message
21
- when :private, :protected
22
- "and will be #{message}"
23
- when nil
24
- "and will be removed"
25
- else
26
- message
21
+ when :private, :protected
22
+ "and will be #{message}"
23
+ when nil
24
+ "and will be removed"
25
+ else
26
+ message
27
27
  end
28
- MIME::Types.logger.warn <<-WARNING.chomp.strip
28
+ MIME::Types.logger.debug <<-WARNING.chomp.strip
29
29
  #{caller(2..2).first}: #{klass}#{level}#{sym} is deprecated #{message}.
30
30
  WARNING
31
31
 
@@ -26,7 +26,7 @@ module MIME
26
26
  end
27
27
 
28
28
  def initialize(_one, _two = nil, _three = nil)
29
- super nil
29
+ super(nil)
30
30
  @logdev = WarnLogDevice.new
31
31
  @formatter = ->(_s, _d, _p, m) { m }
32
32
  end
@@ -45,7 +45,7 @@ class << MIME::Types
45
45
  def lazy_load?
46
46
  return unless ENV.key?("RUBY_MIME_TYPES_LAZY_LOAD")
47
47
 
48
- MIME::Types.logger.warn <<-WARNING.chomp.strip
48
+ MIME::Types.logger.debug <<-WARNING.chomp.strip
49
49
  Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed.
50
50
  WARNING
51
51
 
data/lib/mime/types.rb CHANGED
@@ -125,12 +125,12 @@ class MIME::Types
125
125
  def [](type_id, complete: false, registered: false)
126
126
  matches =
127
127
  case type_id
128
- when MIME::Type
129
- @type_variants[type_id.simplified]
130
- when Regexp
131
- match(type_id)
132
- else
133
- @type_variants[MIME::Type.simplified(type_id)]
128
+ when MIME::Type
129
+ @type_variants[type_id.simplified]
130
+ when Regexp
131
+ match(type_id)
132
+ else
133
+ @type_variants[MIME::Type.simplified(type_id)]
134
134
  end
135
135
 
136
136
  prune_matches(matches, complete, registered).sort { |a, b|
@@ -152,7 +152,7 @@ class MIME::Types
152
152
  # => [application/xml, image/gif, text/xml]
153
153
  def type_for(filename)
154
154
  Array(filename).flat_map { |fn|
155
- @extension_index[fn.chomp.downcase[/\.?([^.]*?)$/, 1]]
155
+ @extension_index[fn.chomp.downcase[/\.?([^.]*?)\z/m, 1]]
156
156
  }.compact.inject(Set.new, :+).sort { |a, b|
157
157
  a.priority_compare(b)
158
158
  }
@@ -165,7 +165,7 @@ class MIME::Types
165
165
  # The last parameter may be the value <tt>:silent</tt> or +true+ which
166
166
  # will suppress duplicate MIME type warnings.
167
167
  def add(*types)
168
- quiet = ((types.last == :silent) || (types.last == true))
168
+ quiet = (types.last == :silent) || (types.last == true)
169
169
 
170
170
  types.each do |mime_type|
171
171
  case mime_type
@@ -187,7 +187,7 @@ class MIME::Types
187
187
  # truthy value to suppress that warning.
188
188
  def add_type(type, quiet = false)
189
189
  if !quiet && @type_variants[type.simplified].include?(type)
190
- MIME::Types.logger.warn <<-WARNING.chomp.strip
190
+ MIME::Types.logger.debug <<-WARNING.chomp.strip
191
191
  Type #{type} is already registered as a variant of #{type.simplified}.
192
192
  WARNING
193
193
  end
@@ -5,7 +5,6 @@ require "fileutils"
5
5
 
6
6
  gem "minitest"
7
7
  require "minitest/focus"
8
- require "minitest-bonus-assertions"
9
8
  require "minitest/hooks"
10
9
 
11
10
  ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "yes"
@@ -266,7 +266,27 @@ describe MIME::Type do
266
266
  end
267
267
 
268
268
  it "is true for an equivalent MIME::Type" do
269
- assert text_plain, mime_type("text/Plain")
269
+ assert text_plain.eql?(mime_type("text/Plain"))
270
+ end
271
+
272
+ it "is true for an equivalent subclass of MIME::Type" do
273
+ subclass = Class.new(MIME::Type)
274
+ assert text_plain.eql?(subclass.new("text/plain"))
275
+ end
276
+ end
277
+
278
+ describe "#hash" do
279
+ it "is the same between #eql? MIME::Type instances" do
280
+ assert_equal text_plain.hash, mime_type("text/plain").hash
281
+ end
282
+
283
+ it "is the same between #eql? MIME::Type instances of different classes" do
284
+ subclass = Class.new(MIME::Type)
285
+ assert_equal text_plain.hash, subclass.new("text/plain").hash
286
+ end
287
+
288
+ it "uses the #simplified value" do
289
+ assert_equal text_plain.hash, mime_type("text/Plain").hash
270
290
  end
271
291
  end
272
292
 
@@ -426,37 +446,53 @@ describe MIME::Type do
426
446
  describe "#to_h" do
427
447
  let(:t) { mime_type("a/b") }
428
448
 
449
+ def assert_has_keys(wanted_keys, actual, msg = nil)
450
+ wanted_keys = Array(wanted_keys).uniq.sort
451
+ actual_keys = if actual.is_a?(Hash)
452
+ actual.keys
453
+ else
454
+ actual.to_h.keys
455
+ end
456
+
457
+ missing = wanted_keys - actual_keys
458
+ pretty_wanted_keys = (wanted_keys + actual_keys).uniq.sort
459
+
460
+ msg = message(msg) {
461
+ "#{mu_pp(actual)} is missing attribute values\n#{diff(pretty_wanted_keys, actual_keys)}"
462
+ }
463
+
464
+ assert missing.empty?, msg
465
+ end
466
+
429
467
  it "has the required keys (content-type, registered, encoding)" do
430
- assert_has_keys t.to_h, %w[content-type registered encoding]
468
+ assert_has_keys %w[content-type registered encoding], t
431
469
  end
432
470
 
433
471
  it "has the docs key if there are documents" do
434
- assert_has_keys mime_type(t) { |v| v.docs = "a" }.to_h, %w[docs]
472
+ assert_has_keys "docs", mime_type(t) { |v| v.docs = "a" }
435
473
  end
436
474
 
437
475
  it "has the extensions key if set" do
438
- assert_has_keys mime_type(t) { |v| v.extensions = "a" }.to_h,
439
- "extensions"
476
+ assert_has_keys "extensions", mime_type(t) { |v| v.extensions = "a" }
440
477
  end
441
478
 
442
479
  it "has the preferred-extension key if set" do
443
- assert_has_keys mime_type(t) { |v| v.preferred_extension = "a" }.to_h,
444
- "preferred-extension"
480
+ assert_has_keys "preferred-extension", mime_type(t) { |v| v.preferred_extension = "a" }
445
481
  end
446
482
 
447
483
  it "has the obsolete key if set" do
448
- assert_has_keys mime_type(t) { |v| v.obsolete = true }.to_h, "obsolete"
484
+ assert_has_keys "obsolete", mime_type(t) { |v| v.obsolete = true }
449
485
  end
450
486
 
451
487
  it "has the obsolete and use-instead keys if set" do
452
- assert_has_keys mime_type(t) { |v|
488
+ assert_has_keys %w[obsolete use-instead], mime_type(t) { |v|
453
489
  v.obsolete = true
454
490
  v.use_instead = "c/d"
455
- }.to_h, %w[obsolete use-instead]
491
+ }
456
492
  end
457
493
 
458
494
  it "has the signature key if set" do
459
- assert_has_keys mime_type(t) { |v| v.signature = true }.to_h, "signature"
495
+ assert_has_keys "signature", mime_type(t) { |v| v.signature = true }
460
496
  end
461
497
  end
462
498
 
@@ -159,6 +159,10 @@ describe MIME::Types do
159
159
  plain_text.add_extensions("xtxt")
160
160
  assert_includes mime_types.type_for("xtxt"), "text/plain"
161
161
  end
162
+
163
+ it "handles newline characters correctly" do
164
+ assert_includes mime_types.type_for("test.pdf\n.txt"), "text/plain"
165
+ end
162
166
  end
163
167
 
164
168
  describe "#count" do
@@ -67,7 +67,7 @@ describe MIME::Types::Cache do
67
67
  it "outputs an error when there is a marshal file incompatibility" do
68
68
  MIME::Types::Cache.save
69
69
  data = File.binread(@cache_file).reverse
70
- File.open(@cache_file, "wb") { |f| f.write(data) }
70
+ File.binwrite(@cache_file, data)
71
71
  MIME::Types.instance_variable_set(:@__types__, nil)
72
72
  assert_output "", /incompatible marshal file format/ do
73
73
  MIME::Types["text/html"]
@@ -100,6 +100,11 @@ describe MIME::Types, "registry" do
100
100
  plain_text.add_extensions("xtxt")
101
101
  assert_includes MIME::Types.type_for("xtxt"), "text/plain"
102
102
  end
103
+
104
+ it "handles newline characters correctly" do
105
+ assert_includes MIME::Types.type_for("test.pdf\n.txt"), "text/plain"
106
+ assert_includes MIME::Types.type_for("test.txt\n.pdf"), "application/pdf"
107
+ end
103
108
  end
104
109
 
105
110
  describe ".count" do
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.1
4
+ version: 3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types-data
@@ -30,72 +30,78 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.14'
33
+ version: '5.20'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.14'
40
+ version: '5.20'
41
41
  - !ruby/object:Gem::Dependency
42
- name: hoe-doofus
42
+ name: hoe
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '3.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5'
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
- version: '1.0'
57
+ version: '3.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5'
55
61
  - !ruby/object:Gem::Dependency
56
- name: hoe-gemspec2
62
+ name: hoe-doofus
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '1.1'
67
+ version: '1.0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '1.1'
74
+ version: '1.0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: hoe-git
76
+ name: hoe-gemspec2
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '1.6'
81
+ version: '1.1'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '1.6'
88
+ version: '1.1'
83
89
  - !ruby/object:Gem::Dependency
84
- name: hoe-rubygems
90
+ name: hoe-git2
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '1.0'
95
+ version: '1.7'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '1.0'
102
+ version: '1.7'
97
103
  - !ruby/object:Gem::Dependency
98
- name: standard
104
+ name: hoe-rubygems
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
107
  - - "~>"
@@ -136,20 +142,6 @@ dependencies:
136
142
  - - "~>"
137
143
  - !ruby/object:Gem::Version
138
144
  version: '1.0'
139
- - !ruby/object:Gem::Dependency
140
- name: minitest-bonus-assertions
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '3.0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '3.0'
153
145
  - !ruby/object:Gem::Dependency
154
146
  name: minitest-hooks
155
147
  requirement: !ruby/object:Gem::Requirement
@@ -185,19 +177,19 @@ dependencies:
185
177
  - !ruby/object:Gem::Version
186
178
  version: '14.0'
187
179
  - !ruby/object:Gem::Dependency
188
- name: simplecov
180
+ name: standard
189
181
  requirement: !ruby/object:Gem::Requirement
190
182
  requirements:
191
183
  - - "~>"
192
184
  - !ruby/object:Gem::Version
193
- version: '0.7'
185
+ version: '1.0'
194
186
  type: :development
195
187
  prerelease: false
196
188
  version_requirements: !ruby/object:Gem::Requirement
197
189
  requirements:
198
190
  - - "~>"
199
191
  - !ruby/object:Gem::Version
200
- version: '0.7'
192
+ version: '1.0'
201
193
  - !ruby/object:Gem::Dependency
202
194
  name: rdoc
203
195
  requirement: !ruby/object:Gem::Requirement
@@ -219,19 +211,19 @@ dependencies:
219
211
  - !ruby/object:Gem::Version
220
212
  version: '7'
221
213
  - !ruby/object:Gem::Dependency
222
- name: hoe
214
+ name: simplecov
223
215
  requirement: !ruby/object:Gem::Requirement
224
216
  requirements:
225
217
  - - "~>"
226
218
  - !ruby/object:Gem::Version
227
- version: '3.23'
219
+ version: '0.21'
228
220
  type: :development
229
221
  prerelease: false
230
222
  version_requirements: !ruby/object:Gem::Requirement
231
223
  requirements:
232
224
  - - "~>"
233
225
  - !ruby/object:Gem::Version
234
- version: '3.23'
226
+ version: '0.21'
235
227
  description: |-
236
228
  The mime-types library provides a library and registry for information about
237
229
  MIME content type definitions. It can be used to determine defined filename
@@ -257,6 +249,7 @@ extra_rdoc_files:
257
249
  - Manifest.txt
258
250
  - README.rdoc
259
251
  files:
252
+ - ".standard.yml"
260
253
  - Code-of-Conduct.md
261
254
  - Contributing.md
262
255
  - History.md
@@ -296,6 +289,7 @@ metadata:
296
289
  source_code_uri: https://github.com/mime-types/ruby-mime-types/
297
290
  bug_tracker_uri: https://github.com/mime-types/ruby-mime-types/issues
298
291
  changelog_uri: https://github.com/mime-types/ruby-mime-types/blob/master/History.md
292
+ rubygems_mfa_required: 'true'
299
293
  post_install_message:
300
294
  rdoc_options:
301
295
  - "--main"
@@ -313,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
307
  - !ruby/object:Gem::Version
314
308
  version: '0'
315
309
  requirements: []
316
- rubygems_version: 3.1.6
310
+ rubygems_version: 3.5.3
317
311
  signing_key:
318
312
  specification_version: 4
319
313
  summary: The mime-types library provides a library and registry for information about