mini_defender 0.1.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/mini_defender/validates_input.rb +13 -1
- data/lib/mini_defender/validator.rb +5 -3
- data/lib/mini_defender/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a99b54a0e9bfe214e233a5aea751b7b06a5ada678cc8fb3c105cf2d564ef141
|
4
|
+
data.tar.gz: 1f4d4944d884b31a96cac3b715d91071a901afaef9c89cb7868a6bdf8ce6f4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a360a9274941bf94e29be3c9c5be597b3c1453cf7c31d50f8f54e435104c8570316e90de4459645f81a458e2f5957168806db5616d39fe2514e8d1ddc0d9aa5
|
7
|
+
data.tar.gz: 861656fde0726eb29ea2484a156039ca728a1bf086e28c72e2e27b833f3f784f5a6b03ecda007003efc7fa0d4feacc9b4f498515cd2399855c17eedb2365b838
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,21 @@ module MiniDefender::ValidatesInput
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def validate!(rules, coerced = false)
|
7
|
-
data = params.to_unsafe_hash.deep_stringify_keys
|
7
|
+
data = cleanse_data(params.to_unsafe_hash.deep_stringify_keys)
|
8
8
|
validator = MiniDefender::Validator.new(rules, data)
|
9
9
|
validator.validate!
|
10
10
|
coerced ? validator.coerced : validator.data
|
11
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def cleanse_data(data)
|
16
|
+
data = data.to_h do |k, v|
|
17
|
+
v = v.strip
|
18
|
+
v = nil if v.blank?
|
19
|
+
[k, v]
|
20
|
+
end
|
21
|
+
|
22
|
+
data.compact
|
23
|
+
end
|
12
24
|
end
|
@@ -50,20 +50,22 @@ module MiniDefender
|
|
50
50
|
next
|
51
51
|
end
|
52
52
|
|
53
|
-
value = @data[k]
|
53
|
+
value = coerced = @data[k]
|
54
54
|
rule_set.each do |rule|
|
55
55
|
next unless rule.active?(self)
|
56
56
|
|
57
57
|
value_included &= !rule.excluded?(self)
|
58
58
|
|
59
|
-
|
59
|
+
if rule.passes?(k, coerced, self)
|
60
|
+
coerced = rule.coerce(coerced)
|
61
|
+
else
|
60
62
|
@errors[k] << rule.error_message(k, value, self)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
66
|
if @errors[k].empty? && value_included
|
65
67
|
@validated[k] = value
|
66
|
-
@coerced[k] =
|
68
|
+
@coerced[k] = coerced
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_defender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ali Alhoshaiyan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|