mini_defender 0.5.8 → 0.6.1

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: 0b22d2146228e92dfadf457e5643cf302660d0270ca7d7bdb5c234d6f77c8c26
4
- data.tar.gz: 6fb0563b3e8ca27291823e57b36d0e80721c72623580c2ddbb81c529ab414ad7
3
+ metadata.gz: e29762e85b9cd347c9a95273d6d08d806b6adc24ff284b6ec5e4e347c4e2b910
4
+ data.tar.gz: 2ea25d48682e25d311f90d33a3b5b8bacaa6720431380b34479eeede78468e3a
5
5
  SHA512:
6
- metadata.gz: 788accd406dee38de6fc5fb0150eee0760400eb1afa1ab5f0f4f8480384f77aa5f9d2b0737fece159c2c361c2f1c375a691b8e008e6bca7a259cb3557db3cc38
7
- data.tar.gz: df80d251d07fd941fe6711ce275b2a5b599548b8b9e31efab1d7893da1f631dbe15dd4768b45683814f7fff4ceaa2ff645e6b0cf2568b22fc7f69ee17ea2b798
6
+ metadata.gz: 6b5411b6d0bd4565a420052b3baceebff4bb1873c42c68b48f566c20533f28fd674f37f4df9bab3e6877d0959e2671fc886d1154e9d6de34508de04bae2c4778
7
+ data.tar.gz: 3707890c60e1c3eccff9ab37287819a3e8997b101c5d74ef37fd2cc7bf5466d5304095607a20e8a3f2ab06de0cae22d4055b1f15a5243785511807d77680fdb6
@@ -1,19 +1,86 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class MiniDefender::Rules::Integer < MiniDefender::Rule
4
+ attr_reader :mode
5
+ attr_reader :parsed
6
+
7
+ DIGIT_MAP = {
8
+ # Arabic-Indic Digits
9
+ "\u0660" => '0',
10
+ "\u0661" => '1',
11
+ "\u0662" => '2',
12
+ "\u0663" => '3',
13
+ "\u0664" => '4',
14
+ "\u0665" => '5',
15
+ "\u0666" => '6',
16
+ "\u0667" => '7',
17
+ "\u0668" => '8',
18
+ "\u0669" => '9',
19
+
20
+ # Extended Arabic-Indic Digits
21
+ "\u06F0" => '0',
22
+ "\u06F1" => '1',
23
+ "\u06F2" => '2',
24
+ "\u06F3" => '3',
25
+ "\u06F4" => '4',
26
+ "\u06F5" => '5',
27
+ "\u06F6" => '6',
28
+ "\u06F7" => '7',
29
+ "\u06F8" => '8',
30
+ "\u06F9" => '9',
31
+ }
32
+
33
+ def initialize(mode = 'strict')
34
+ @mode = mode
35
+ end
36
+
4
37
  def self.signature
5
38
  'integer'
6
39
  end
7
40
 
41
+ def self.make(args)
42
+ new(args[0] || 'strict')
43
+ end
44
+
8
45
  def coerce(value)
9
- value.to_i
46
+ @parsed
10
47
  end
11
48
 
12
49
  def passes?(attribute, value, validator)
13
- value.is_a?(Integer) || value.is_a?(String) && value.match?(/^\d+$/)
50
+ # Avoid converting integers to string and back
51
+ if value.is_a?(Integer)
52
+ @parsed = value
53
+ return true
54
+ end
55
+
56
+ # Remove leading zero so Integer will not treat it as octal
57
+ value = value
58
+ .to_s
59
+ .gsub(/^0+/, '')
60
+
61
+ if @mode == 'relaxed'
62
+ value = normalize_digits(value)
63
+ end
64
+
65
+ @parsed = Integer(value)
66
+ rescue
67
+ false
14
68
  end
15
69
 
16
70
  def message(attribute, value, validator)
17
71
  "The value must be an integer."
18
72
  end
73
+
74
+ def normalize_digits(data)
75
+ # Check if arabic digits exist or avoid expensive string creation operation
76
+ unless data.match?(/[\u0660-\u0669\u06F0-\u06F9]/)
77
+ return data
78
+ end
79
+
80
+ DIGIT_MAP.each do |k, v|
81
+ data = data.gsub(k, v)
82
+ end
83
+
84
+ data
85
+ end
19
86
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniDefender
4
- VERSION = "0.5.8"
4
+ VERSION = "0.6.1"
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.8
4
+ version: 0.6.1
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-02-20 00:00:00.000000000 Z
11
+ date: 2024-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport