carrierwave 0.11.1 → 0.11.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1689fd908e56b671c45e5cb1eebe3ec938a4df
|
4
|
+
data.tar.gz: 89668d77484c786139f513dc1b82c82879da4e11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a03780cb6e64ad439c1f12378be2f4392617dbbe9f83329eccc6bc05064385e0e95a4b4609e32d922a0ce6d5543bbc795eb4abb8e429d5e366040fdfa3c82bfd
|
7
|
+
data.tar.gz: ee26ab882ed995b677c38e6064843101633a07166cf2dda0e522bf1b13eb7a30a373312d67b786bc86365fd3ef4cb974f8f57a564dafbf9eafaf1c60b7e3e3e8
|
data/lib/carrierwave/uploader.rb
CHANGED
@@ -11,6 +11,8 @@ require "carrierwave/uploader/download"
|
|
11
11
|
require "carrierwave/uploader/remove"
|
12
12
|
require "carrierwave/uploader/extension_whitelist"
|
13
13
|
require "carrierwave/uploader/extension_blacklist"
|
14
|
+
require "carrierwave/uploader/content_type_whitelist"
|
15
|
+
require "carrierwave/uploader/content_type_blacklist"
|
14
16
|
require "carrierwave/uploader/processing"
|
15
17
|
require "carrierwave/uploader/versions"
|
16
18
|
require "carrierwave/uploader/default_url"
|
@@ -53,6 +55,8 @@ module CarrierWave
|
|
53
55
|
include CarrierWave::Uploader::Remove
|
54
56
|
include CarrierWave::Uploader::ExtensionWhitelist
|
55
57
|
include CarrierWave::Uploader::ExtensionBlacklist
|
58
|
+
include CarrierWave::Uploader::ContentTypeWhitelist
|
59
|
+
include CarrierWave::Uploader::ContentTypeBlacklist
|
56
60
|
include CarrierWave::Uploader::Processing
|
57
61
|
include CarrierWave::Uploader::Versions
|
58
62
|
include CarrierWave::Uploader::DefaultUrl
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Uploader
|
3
|
+
module ContentTypeBlacklist
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before :cache, :check_content_type_blacklist!
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Override this method in your uploader to provide a blacklist of files content types
|
12
|
+
# which are not allowed to be uploaded.
|
13
|
+
# Not only strings but Regexp are allowed as well.
|
14
|
+
#
|
15
|
+
# === Returns
|
16
|
+
#
|
17
|
+
# [NilClass, String, Regexp, Array[String, Regexp]] a blacklist of content types which are not allowed to be uploaded
|
18
|
+
#
|
19
|
+
# === Examples
|
20
|
+
#
|
21
|
+
# def content_type_blacklist
|
22
|
+
# %w(text/json application/json)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Basically the same, but using a Regexp:
|
26
|
+
#
|
27
|
+
# def content_type_blacklist
|
28
|
+
# [/(text|application)\/json/]
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
def content_type_blacklist; end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def check_content_type_blacklist!(new_file)
|
36
|
+
content_type = new_file.content_type
|
37
|
+
if content_type_blacklist && blacklisted_content_type?(content_type)
|
38
|
+
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_blacklist_error", content_type: content_type)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def blacklisted_content_type?(content_type)
|
43
|
+
Array(content_type_blacklist).any? { |item| content_type =~ /#{item}/ }
|
44
|
+
end
|
45
|
+
|
46
|
+
end # ContentTypeBlacklist
|
47
|
+
end # Uploader
|
48
|
+
end # CarrierWave
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Uploader
|
3
|
+
module ContentTypeWhitelist
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before :cache, :check_content_type_whitelist!
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Override this method in your uploader to provide a whitelist of files content types
|
12
|
+
# which are allowed to be uploaded.
|
13
|
+
# Not only strings but Regexp are allowed as well.
|
14
|
+
#
|
15
|
+
# === Returns
|
16
|
+
#
|
17
|
+
# [NilClass, String, Regexp, Array[String, Regexp]] a whitelist of content types which are allowed to be uploaded
|
18
|
+
#
|
19
|
+
# === Examples
|
20
|
+
#
|
21
|
+
# def content_type_whitelist
|
22
|
+
# %w(text/json application/json)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Basically the same, but using a Regexp:
|
26
|
+
#
|
27
|
+
# def content_type_whitelist
|
28
|
+
# [/(text|application)\/json/]
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
def content_type_whitelist; end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def check_content_type_whitelist!(new_file)
|
36
|
+
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)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def whitelisted_content_type?(content_type)
|
43
|
+
Array(content_type_whitelist).any? { |item| content_type =~ /#{item}/ }
|
44
|
+
end
|
45
|
+
|
46
|
+
end # ContentTypeWhitelist
|
47
|
+
end # Uploader
|
48
|
+
end # CarrierWave
|
data/lib/carrierwave/version.rb
CHANGED
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: 0.11.
|
4
|
+
version: 0.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -306,6 +306,8 @@ files:
|
|
306
306
|
- lib/carrierwave/uploader/cache.rb
|
307
307
|
- lib/carrierwave/uploader/callbacks.rb
|
308
308
|
- lib/carrierwave/uploader/configuration.rb
|
309
|
+
- lib/carrierwave/uploader/content_type_blacklist.rb
|
310
|
+
- lib/carrierwave/uploader/content_type_whitelist.rb
|
309
311
|
- lib/carrierwave/uploader/default_url.rb
|
310
312
|
- lib/carrierwave/uploader/download.rb
|
311
313
|
- lib/carrierwave/uploader/extension_blacklist.rb
|