saneitized 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/saneitized/array.rb +5 -4
- data/lib/saneitized/converter.rb +4 -3
- data/lib/saneitized/hash.rb +4 -3
- data/lib/saneitized/version.rb +1 -1
- data/spec/saneitized/converter_spec.rb +12 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab347d813be1f3280e082c1c98ac2c2239658a6
|
4
|
+
data.tar.gz: 11878e23a57706b167dd112921aa433ef1b18eb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13e249df3f2bdce3dc78bde0de6f22df736eb4ce82b38e5c92b99ebfe58633547ae470fb3542e0a8ddba365d3b9a611082cc7e53b49dec1933f4cf488b2f7fec
|
7
|
+
data.tar.gz: 49dae3f6dd291f4a1385128e57dcd7045c925b6d13d8f9ee6906bd1044618796021a59b2d944e28162b9d17836f6fa4ccb5168397f3248d86bdf5061e13269ff
|
data/lib/saneitized/array.rb
CHANGED
@@ -3,17 +3,18 @@ module Saneitized
|
|
3
3
|
|
4
4
|
class Array < SimpleDelegator
|
5
5
|
|
6
|
-
def initialize(array = [])
|
7
|
-
|
6
|
+
def initialize(array = [], options = {})
|
7
|
+
@options = options
|
8
|
+
super(array.map{|item| Saneitized.convert(item, options)})
|
8
9
|
self
|
9
10
|
end
|
10
11
|
|
11
12
|
def []=(index, value)
|
12
|
-
super index, Saneitized.convert(value)
|
13
|
+
super index, Saneitized.convert(value, @options)
|
13
14
|
end
|
14
15
|
|
15
16
|
def << (value)
|
16
|
-
super Saneitized.convert(value)
|
17
|
+
super Saneitized.convert(value, @options)
|
17
18
|
end
|
18
19
|
|
19
20
|
def push(*args)
|
data/lib/saneitized/converter.rb
CHANGED
@@ -5,15 +5,16 @@ module Saneitized
|
|
5
5
|
|
6
6
|
def self.convert(unknown, options = {})
|
7
7
|
options[:blacklist] ||= nil
|
8
|
-
|
9
|
-
return Saneitized::
|
8
|
+
|
9
|
+
return Saneitized::Hash.new(unknown, options) if unknown.is_a? ::Hash
|
10
|
+
return Saneitized::Array.new(unknown, options) if unknown.is_a? ::Array
|
10
11
|
return unknown unless unknown.is_a? String #Only attempt to convert string
|
11
12
|
return unknown if Array(options[:blacklist]).include?(unknown)
|
12
13
|
|
13
14
|
%w(true false nil integer float json time).each do |type|
|
14
15
|
value = Converter.send(type + '?', unknown)
|
15
16
|
next if value == :nope
|
16
|
-
return (type == 'json') ? convert(value) : value
|
17
|
+
return (type == 'json') ? convert(value, options) : value
|
17
18
|
end
|
18
19
|
|
19
20
|
unknown
|
data/lib/saneitized/hash.rb
CHANGED
@@ -2,15 +2,16 @@ module Saneitized
|
|
2
2
|
|
3
3
|
class Hash < SimpleDelegator
|
4
4
|
|
5
|
-
def initialize(hash = {})
|
5
|
+
def initialize(hash = {}, options = {})
|
6
|
+
@options = options
|
6
7
|
new_hash = {}
|
7
|
-
hash.each do |key, value| new_hash[key] = Saneitized.convert(value) end
|
8
|
+
hash.each do |key, value| new_hash[key] = Saneitized.convert(value, options) end
|
8
9
|
super(new_hash)
|
9
10
|
self
|
10
11
|
end
|
11
12
|
|
12
13
|
def []=(key, value)
|
13
|
-
super key, Saneitized.convert(value)
|
14
|
+
super key, Saneitized.convert(value, @options)
|
14
15
|
end
|
15
16
|
|
16
17
|
def merge!(*args, &block)
|
data/lib/saneitized/version.rb
CHANGED
@@ -68,13 +68,19 @@ describe Saneitized do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
context 'with blacklist' do
|
72
|
+
it 'should not convertet blacklisted item' do
|
73
|
+
expect(Saneitized.convert('day', blacklist:'day')).to eql 'day'
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
it 'should not converter item in blacklist array' do
|
77
|
+
expect(Saneitized.convert('day', blacklist:%w(hour day))).to eql 'day'
|
78
|
+
end
|
78
79
|
|
80
|
+
it 'should not convert item in hash in blacklist' do
|
81
|
+
expected = { 'today' => ['day', 'month', 'week'] }
|
82
|
+
expect(Saneitized.convert('{"today":["day","month","week"]}', blacklist:%w(day month week))).to eq expected
|
83
|
+
end
|
84
|
+
end
|
79
85
|
end
|
80
86
|
end
|