carrierwave 2.0.1 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

@@ -8,39 +8,51 @@ module CarrierWave
8
8
  end
9
9
 
10
10
  ##
11
- # Override this method in your uploader to provide a whitelist of files content types
11
+ # Override this method in your uploader to provide an allowlist of files content types
12
12
  # which are allowed to be uploaded.
13
13
  # Not only strings but Regexp are allowed as well.
14
14
  #
15
15
  # === Returns
16
16
  #
17
- # [NilClass, String, Regexp, Array[String, Regexp]] a whitelist of content types which are allowed to be uploaded
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] an allowlist of content types which are allowed to be uploaded
18
18
  #
19
19
  # === Examples
20
20
  #
21
- # def content_type_whitelist
21
+ # def content_type_allowlist
22
22
  # %w(text/json application/json)
23
23
  # end
24
24
  #
25
25
  # Basically the same, but using a Regexp:
26
26
  #
27
- # def content_type_whitelist
27
+ # def content_type_allowlist
28
28
  # [/(text|application)\/json/]
29
29
  # end
30
30
  #
31
- def content_type_whitelist; end
31
+ def content_type_allowlist
32
+ if respond_to?(:content_type_whitelist)
33
+ ActiveSupport::Deprecation.warn "#content_type_whitelist is deprecated, use #content_type_allowlist instead." unless instance_variable_defined?(:@content_type_whitelist_warned)
34
+ @content_type_whitelist_warned = true
35
+ content_type_whitelist
36
+ end
37
+ end
32
38
 
33
39
  private
34
40
 
35
41
  def check_content_type_whitelist!(new_file)
42
+ return unless content_type_allowlist
43
+
36
44
  content_type = new_file.content_type
37
- if content_type_whitelist && !whitelisted_content_type?(content_type)
38
- raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type, allowed_types: Array(content_type_whitelist).join(", "))
45
+ if !whitelisted_content_type?(content_type)
46
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type,
47
+ allowed_types: Array(content_type_allowlist).join(", "), default: :"errors.messages.content_type_allowlist_error")
39
48
  end
40
49
  end
41
50
 
42
51
  def whitelisted_content_type?(content_type)
43
- Array(content_type_whitelist).any? { |item| content_type =~ /#{item}/ }
52
+ Array(content_type_allowlist).any? do |item|
53
+ item = Regexp.quote(item) if item.class != Regexp
54
+ content_type =~ /#{item}/
55
+ end
44
56
  end
45
57
 
46
58
  end # ContentTypeWhitelist
@@ -8,43 +8,51 @@ module CarrierWave
8
8
  end
9
9
 
10
10
  ##
11
- # Override this method in your uploader to provide a black list of extensions which
11
+ # Override this method in your uploader to provide a denylist of extensions which
12
12
  # are prohibited to be uploaded. Compares the file's extension case insensitive.
13
13
  # Furthermore, not only strings but Regexp are allowed as well.
14
14
  #
15
- # When using a Regexp in the black list, `\A` and `\z` are automatically added to
15
+ # When using a Regexp in the denylist, `\A` and `\z` are automatically added to
16
16
  # the Regexp expression, also case insensitive.
17
17
  #
18
18
  # === Returns
19
19
 
20
- # [NilClass, String, Regexp, Array[String, Regexp]] a black list of extensions which are prohibited to be uploaded
20
+ # [NilClass, String, Regexp, Array[String, Regexp]] a deny list of extensions which are prohibited to be uploaded
21
21
  #
22
22
  # === Examples
23
23
  #
24
- # def extension_blacklist
24
+ # def extension_denylist
25
25
  # %w(swf tiff)
26
26
  # end
27
27
  #
28
28
  # Basically the same, but using a Regexp:
29
29
  #
30
- # def extension_blacklist
30
+ # def extension_denylist
31
31
  # [/swf/, 'tiff']
32
32
  # end
33
33
  #
34
-
35
- def extension_blacklist; end
34
+ def extension_denylist
35
+ if respond_to?(:extension_blacklist)
36
+ ActiveSupport::Deprecation.warn "#extension_blacklist is deprecated, use #extension_denylist instead." unless instance_variable_defined?(:@extension_blacklist_warned)
37
+ @extension_blacklist_warned = true
38
+ extension_blacklist
39
+ end
40
+ end
36
41
 
37
42
  private
38
43
 
39
44
  def check_extension_blacklist!(new_file)
45
+ return unless extension_denylist
46
+
40
47
  extension = new_file.extension.to_s
41
- if extension_blacklist && blacklisted_extension?(extension)
42
- raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_blacklist_error", extension: new_file.extension.inspect, prohibited_types: Array(extension_blacklist).join(", "))
48
+ if blacklisted_extension?(extension)
49
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_blacklist_error", extension: new_file.extension.inspect,
50
+ prohibited_types: Array(extension_denylist).join(", "), default: :"errors.messages.extension_denylist_error")
43
51
  end
44
52
  end
45
53
 
46
54
  def blacklisted_extension?(extension)
47
- Array(extension_blacklist).any? { |item| extension =~ /\A#{item}\z/i }
55
+ Array(extension_denylist).any? { |item| extension =~ /\A#{item}\z/i }
48
56
  end
49
57
  end
50
58
  end
@@ -8,45 +8,54 @@ module CarrierWave
8
8
  end
9
9
 
10
10
  ##
11
- # Override this method in your uploader to provide a white list of extensions which
11
+ # Override this method in your uploader to provide an allowlist of extensions which
12
12
  # are allowed to be uploaded. Compares the file's extension case insensitive.
13
13
  # Furthermore, not only strings but Regexp are allowed as well.
14
14
  #
15
- # When using a Regexp in the white list, `\A` and `\z` are automatically added to
15
+ # When using a Regexp in the allowlist, `\A` and `\z` are automatically added to
16
16
  # the Regexp expression, also case insensitive.
17
17
  #
18
18
  # === Returns
19
19
  #
20
- # [NilClass, String, Regexp, Array[String, Regexp]] a white list of extensions which are allowed to be uploaded
20
+ # [NilClass, String, Regexp, Array[String, Regexp]] an allowlist of extensions which are allowed to be uploaded
21
21
  #
22
22
  # === Examples
23
23
  #
24
- # def extension_whitelist
24
+ # def extension_allowlist
25
25
  # %w(jpg jpeg gif png)
26
26
  # end
27
27
  #
28
28
  # Basically the same, but using a Regexp:
29
29
  #
30
- # def extension_whitelist
30
+ # def extension_allowlist
31
31
  # [/jpe?g/, 'gif', 'png']
32
32
  # end
33
33
  #
34
- def extension_whitelist; end
34
+ def extension_allowlist
35
+ if respond_to?(:extension_whitelist)
36
+ ActiveSupport::Deprecation.warn "#extension_whitelist is deprecated, use #extension_allowlist instead." unless instance_variable_defined?(:@extension_whitelist_warned)
37
+ @extension_whitelist_warned = true
38
+ extension_whitelist
39
+ end
40
+ end
35
41
 
36
42
  private
37
43
 
38
44
  def check_extension_whitelist!(new_file)
45
+ return unless extension_allowlist
46
+
39
47
  extension = new_file.extension.to_s
40
- if extension_whitelist && !whitelisted_extension?(extension)
41
- raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_whitelist_error", extension: new_file.extension.inspect, allowed_types: Array(extension_whitelist).join(", "))
48
+ if !whitelisted_extension?(extension)
49
+ # Look for whitelist first, then fallback to allowlist
50
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_whitelist_error", extension: new_file.extension.inspect,
51
+ allowed_types: Array(extension_allowlist).join(", "), default: :"errors.messages.extension_allowlist_error")
42
52
  end
43
53
  end
44
54
 
45
55
  def whitelisted_extension?(extension)
46
56
  downcase_extension = extension.downcase
47
- Array(extension_whitelist).any? { |item| downcase_extension =~ /\A#{item}\z/i }
57
+ Array(extension_allowlist).any? { |item| downcase_extension =~ /\A#{item}\z/i }
48
58
  end
49
-
50
59
  end # ExtensionWhitelist
51
60
  end # Uploader
52
61
  end # CarrierWave
@@ -15,9 +15,12 @@ module CarrierWave
15
15
  # [String] the location where this file is accessible via a url
16
16
  #
17
17
  def url(options = {})
18
- if file.respond_to?(:url) && !(tmp_url = file.url).blank?
19
- file.method(:url).arity.zero? ? tmp_url : file.url(options)
20
- elsif file.respond_to?(:path)
18
+ if file.respond_to?(:url)
19
+ tmp_url = file.method(:url).arity.zero? ? file.url : file.url(options)
20
+ return tmp_url if tmp_url.present?
21
+ end
22
+
23
+ if file.respond_to?(:path)
21
24
  path = encode_path(file.path.sub(File.expand_path(root), ''))
22
25
 
23
26
  if host = asset_host
@@ -23,7 +23,7 @@ module CarrierWave
23
23
  prepend Module.new {
24
24
  def initialize(*)
25
25
  super
26
- @versions = nil
26
+ @versions, @versions_to_cache, @versions_to_store = nil
27
27
  end
28
28
  }
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "2.0.1"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -33,9 +33,9 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
33
33
  # process resize_to_fit: [50, 50]
34
34
  # end
35
35
 
36
- # Add a white list of extensions which are allowed to be uploaded.
36
+ # Add an allowlist of extensions which are allowed to be uploaded.
37
37
  # For images you might use something like this:
38
- # def extension_whitelist
38
+ # def extension_allowlist
39
39
  # %w(jpg jpeg gif png)
40
40
  # end
41
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-31 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.1'
69
69
  - !ruby/object:Gem::Dependency
70
- name: mimemagic
70
+ name: marcel
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.3.0
75
+ version: 1.0.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.3.0
82
+ version: 1.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: addressable
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ssrf_filter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: pg
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
166
  version: '3.4'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec-retry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: webmock
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +213,9 @@ dependencies:
185
213
  - - "~>"
186
214
  - !ruby/object:Gem::Version
187
215
  version: '1.7'
216
+ - - "!="
217
+ - !ruby/object:Gem::Version
218
+ version: 1.12.1
188
219
  type: :development
189
220
  prerelease: false
190
221
  version_requirements: !ruby/object:Gem::Requirement
@@ -192,6 +223,9 @@ dependencies:
192
223
  - - "~>"
193
224
  - !ruby/object:Gem::Version
194
225
  version: '1.7'
226
+ - - "!="
227
+ - !ruby/object:Gem::Version
228
+ version: 1.12.1
195
229
  - !ruby/object:Gem::Dependency
196
230
  name: fog-local
197
231
  requirement: !ruby/object:Gem::Requirement
@@ -238,14 +272,14 @@ dependencies:
238
272
  name: rmagick
239
273
  requirement: !ruby/object:Gem::Requirement
240
274
  requirements:
241
- - - "~>"
275
+ - - ">="
242
276
  - !ruby/object:Gem::Version
243
277
  version: '2.16'
244
278
  type: :development
245
279
  prerelease: false
246
280
  version_requirements: !ruby/object:Gem::Requirement
247
281
  requirements:
248
- - - "~>"
282
+ - - ">="
249
283
  - !ruby/object:Gem::Version
250
284
  version: '2.16'
251
285
  - !ruby/object:Gem::Dependency
@@ -290,6 +324,20 @@ dependencies:
290
324
  - - ">="
291
325
  - !ruby/object:Gem::Version
292
326
  version: '0'
327
+ - !ruby/object:Gem::Dependency
328
+ name: pry-byebug
329
+ requirement: !ruby/object:Gem::Requirement
330
+ requirements:
331
+ - - ">="
332
+ - !ruby/object:Gem::Version
333
+ version: '0'
334
+ type: :development
335
+ prerelease: false
336
+ version_requirements: !ruby/object:Gem::Requirement
337
+ requirements:
338
+ - - ">="
339
+ - !ruby/object:Gem::Version
340
+ version: '0'
293
341
  description: Upload files in your Ruby applications, map them to a range of ORMs,
294
342
  store them on different backends.
295
343
  email:
@@ -312,6 +360,7 @@ files:
312
360
  - lib/carrierwave/processing.rb
313
361
  - lib/carrierwave/processing/mini_magick.rb
314
362
  - lib/carrierwave/processing/rmagick.rb
363
+ - lib/carrierwave/processing/vips.rb
315
364
  - lib/carrierwave/sanitized_file.rb
316
365
  - lib/carrierwave/storage.rb
317
366
  - lib/carrierwave/storage/abstract.rb
@@ -347,7 +396,7 @@ homepage: https://github.com/carrierwaveuploader/carrierwave
347
396
  licenses:
348
397
  - MIT
349
398
  metadata: {}
350
- post_install_message:
399
+ post_install_message:
351
400
  rdoc_options:
352
401
  - "--main"
353
402
  require_paths:
@@ -363,8 +412,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
363
412
  - !ruby/object:Gem::Version
364
413
  version: '0'
365
414
  requirements: []
366
- rubygems_version: 3.0.3
367
- signing_key:
415
+ rubygems_version: 3.1.2
416
+ signing_key:
368
417
  specification_version: 4
369
418
  summary: Ruby file upload library
370
419
  test_files: []