mini_defender 0.5.1 → 0.5.3

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: 36f0ca2e9d174da94e991c9eed6300ae0f0315ab57b3d9372921726261318c67
4
- data.tar.gz: a4f29b8f5558008c1f5b992722a8ab9dd07dbc93d51d7ec288bd3be5e9d1d91b
3
+ metadata.gz: 87731b96739bb1b69873c678f424ab5a9e5edf8ff2c084803582865fb6ce353b
4
+ data.tar.gz: 0e2c1516a69cfa689cccea7a2013bec0817ea9790831986fbe2fff79f51945c0
5
5
  SHA512:
6
- metadata.gz: 885a3ff5f6a337246c9b47e6ac21b0e9dc21067a11c49d7af2d9135d66f6ab878a620b9f73cafa5b1316d5edc2d74f709f924e37309bbe74bb596500abe8348b
7
- data.tar.gz: 3d6a38389f37816a4b6ebbadd7700b6c628e7011c42dfbe0a07ee907f0d354b9b7aaed18179ad97c8350ea01948966ee47182b40e5630370761a5487c58fbe97
6
+ metadata.gz: d5493f26115c5833ca54f55d4d551751fcd975b6a3c3c4ee8fe53b197f9c78c088d545d60751e026b22598549c3561593023b39b5cc17c8256d952e84f9b4ea1
7
+ data.tar.gz: ae08110a394548937b2ee193e583399e994f8cb82b6d828c5768d5ffb7cbfaaf663996ec0d9ad61d0d25c06de61d00dad06f1f722640800949dd5142cb1545ef
@@ -16,6 +16,13 @@ class MiniDefender::Rule
16
16
  true
17
17
  end
18
18
 
19
+ # Priority is used to sort rules in a rule set to allow rules to validate data
20
+ # before rules that will radically change data
21
+ # @return [Integer]
22
+ def priority
23
+ 100
24
+ end
25
+
19
26
  # @param [MiniDefender::Validator] validator
20
27
  # @return [Boolean]
21
28
  def implicit?(validator)
@@ -13,6 +13,10 @@ class MiniDefender::Rules::Array < MiniDefender::Rule
13
13
  new(args[0] || 'none')
14
14
  end
15
15
 
16
+ def priority
17
+ 500
18
+ end
19
+
16
20
  def coerce(value)
17
21
  @data_mode == 'all' ? value : []
18
22
  end
@@ -19,6 +19,10 @@ class MiniDefender::Rules::Hash < MiniDefender::Rule
19
19
  )
20
20
  end
21
21
 
22
+ def priority
23
+ 500
24
+ end
25
+
22
26
  def coerce(value)
23
27
  @data_mode == 'all' ? value : {}
24
28
  end
@@ -30,6 +34,10 @@ class MiniDefender::Rules::Hash < MiniDefender::Rule
30
34
  def passes?(attribute, value, validator)
31
35
  passes = value.is_a?(Hash)
32
36
 
37
+ unless passes
38
+ return false
39
+ end
40
+
33
41
  if @key_type == 'string'
34
42
  passes &= value.all? { |k, _| k.is_a?(String) }
35
43
  end
@@ -11,16 +11,23 @@ module MiniDefender
11
11
  end
12
12
 
13
13
  def init_set(rule_set)
14
- rule_set = rule_set.split('|') if rule_set.is_a?(String)
15
- raise ArgumentError, 'Rule set must be a string or an array' unless rule_set.is_a?(Array)
14
+ if rule_set.is_a?(String)
15
+ rule_set = rule_set.split('|')
16
+ end
17
+
18
+ unless rule_set.is_a?(Array)
19
+ raise ArgumentError, 'Rule set must be a string or an array'
20
+ end
16
21
 
17
- rule_set.map do |rule|
22
+ rule_set = rule_set.map do |rule|
18
23
  unless rule.is_a?(String) || rule.is_a?(Rule)
19
24
  raise ArgumentError, 'Rule must be a string or an instance of MiniDefender::Rule'
20
25
  end
21
26
 
22
27
  rule.is_a?(String) ? init_rule(rule) : rule
23
28
  end
29
+
30
+ rule_set.sort_by! { |r| r.priority }
24
31
  end
25
32
 
26
33
  def init_rule(signature)
@@ -62,7 +62,7 @@ module MiniDefender
62
62
 
63
63
  value_included &= !rule.excluded?(self)
64
64
 
65
- if rule.passes?(k, value, self)
65
+ if rule.passes?(k, coerced, self)
66
66
  coerced = rule.coerce(coerced)
67
67
  force_coerce = rule.force_coerce?
68
68
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniDefender
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.3"
5
5
  end
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.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Alhoshaiyan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport