saneitized 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7c7d693f5788a72925fc71286dbb0763beec6bb
4
- data.tar.gz: f8af45cfe6328a8ceca644fba63b876b77a505a4
3
+ metadata.gz: 1ab347d813be1f3280e082c1c98ac2c2239658a6
4
+ data.tar.gz: 11878e23a57706b167dd112921aa433ef1b18eb9
5
5
  SHA512:
6
- metadata.gz: 4e785b779cf22c52d537d00eed01ce80b38303da62a511d323fbe5d7cbe6af87184f4f9419aaa7c30475612afa7dc2d9291910192b956f78655b47b3eeac762b
7
- data.tar.gz: 78039489fec19a1f3ac16562e20894d2602f1ecc4c3e0ef3acf3814ce3b5094c81eca7016dd0a0ed22d220503b94b85c758dd74cb671cfa3c986a07f3a4d2887
6
+ metadata.gz: 13e249df3f2bdce3dc78bde0de6f22df736eb4ce82b38e5c92b99ebfe58633547ae470fb3542e0a8ddba365d3b9a611082cc7e53b49dec1933f4cf488b2f7fec
7
+ data.tar.gz: 49dae3f6dd291f4a1385128e57dcd7045c925b6d13d8f9ee6906bd1044618796021a59b2d944e28162b9d17836f6fa4ccb5168397f3248d86bdf5061e13269ff
@@ -3,17 +3,18 @@ module Saneitized
3
3
 
4
4
  class Array < SimpleDelegator
5
5
 
6
- def initialize(array = [])
7
- super(array.map{|item| Saneitized.convert(item)})
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)
@@ -5,15 +5,16 @@ module Saneitized
5
5
 
6
6
  def self.convert(unknown, options = {})
7
7
  options[:blacklist] ||= nil
8
- return Saneitized::Hash.new(unknown) if unknown.is_a? ::Hash
9
- return Saneitized::Array.new(unknown) if unknown.is_a? ::Array
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Saneitized
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -68,13 +68,19 @@ describe Saneitized do
68
68
  end
69
69
  end
70
70
 
71
- it 'should respect blacklist' do
72
- expect(Saneitized.convert('day', blacklist:'day')).to eql 'day'
73
- end
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
- it 'should respect array blacklist' do
76
- expect(Saneitized.convert('day', blacklist:%w(hour day))).to eql 'day'
77
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saneitized
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Guest