mini_defender 0.2.0 → 0.3.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: 558b5d94318a81f2f82af39e68f2945063310dd648cbdc7dce7b11db2452d331
4
- data.tar.gz: b110e5e0d706c60b6e26681906c555e8b2554f9d4fcd518e27a5d2cf803f3da2
3
+ metadata.gz: d4266ed9c9b60525dc1827d8a72e2c9ef2864e05fbe5357cd4f92ee5084b8e36
4
+ data.tar.gz: 61ec8c2c5a397766c435ca7cbccbe04d0b5d12f5476a7e0358b6f2a7f5b0e398
5
5
  SHA512:
6
- metadata.gz: a01a92db5349fa2273418c6e12477d66d59bc160f7b16d21ff6f9953b3608433428e2fd6b13b35193c1ad5a69445c25e22bb746ef27ce0737d6d4c9e6a79e78a
7
- data.tar.gz: 45f4354582db5e8e1a73a53037f162f35505b334bf8fa4ac1d8560809df4d6b103790c3753886d0cd8b0fae041b35c6b49ee0bb26fe5863a2bcc3d4cbd6c89b5
6
+ metadata.gz: 4c6329ba8253c026729ba1b1c25fb42cc89061c1d75486b4256cd15636c9707a4319e521324bba95bbdc1522d1e6306b225602baa7d1c1233d81e22224b36bad
7
+ data.tar.gz: 76dbac54f35486ecb7c331ec9aeb1434507b92ab9e5d0ba98a220a088c87a29e909a989467f13c04c2149a1321cc4e7432694077749044fb39fe6aa5cc98b83f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-04-05
4
+
5
+ - Add cleansing for data before validation
6
+
7
+
3
8
  ## [0.1.0] - 2022-09-22
4
9
 
5
10
  - Initial release
@@ -4,9 +4,28 @@ 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, depth = 1)
16
+ return data if depth > 16
17
+
18
+ case data
19
+ when Array
20
+ data.map{ |v| cleanse_data(v, depth + 1) }.reject(&:nil?)
21
+ when Hash
22
+ data.to_h{ |k, v| [k, cleanse_data(v, depth + 1)] }.compact
23
+ when Numeric, TrueClass, FalseClass, NilClass
24
+ data
25
+ else
26
+ data = data.to_s.strip
27
+ data = nil if data == ''
28
+ data
29
+ end
30
+ end
12
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniDefender
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.2"
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.2.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Alhoshaiyan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-09 00:00:00.000000000 Z
11
+ date: 2023-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport