input_sanitizer 0.5.0 → 0.6.0
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 +4 -4
- data/.github/workflows/ci.yaml +2 -1
- data/.gitignore +2 -0
- data/CHANGELOG +3 -0
- data/lib/input_sanitizer/v2/nested_sanitizer_factory.rb +20 -0
- data/lib/input_sanitizer/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/v2/payload_sanitizer_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f76190c3f31a2a1cd2a3372fcda7bad0e107b621ec3f34cc46ef5a1724b08e
|
4
|
+
data.tar.gz: 4b4400b8f4305308dd076f3a9092a9606fe48860809fadda7a2029cf8fcb57fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5c9fcd7ff42c69d76fe7c266972e12e18a50bd09a325ef8b3dd02321f205a8596c4eab2ac5e8eea4b42a4761198a0f6d7ecdfeb9b052764dfb99d048698c43b
|
7
|
+
data.tar.gz: 8137f9b0b246eb3fdbf74d828bab6f3d97fe5c79616eac19821f727bf0229e277e7d6056bbef2836fd1658dc2766955a95786cf9645d927339a81039028661d2
|
data/.github/workflows/ci.yaml
CHANGED
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -8,10 +8,30 @@ class InputSanitizer::V2::NestedSanitizerFactory
|
|
8
8
|
true
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
class HashExpected
|
13
|
+
def initialize(value)
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
false
|
19
|
+
end
|
20
|
+
|
21
|
+
def cleaned
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def errors
|
26
|
+
[InputSanitizer::TypeMismatchError.new(@value, :hash)]
|
27
|
+
end
|
28
|
+
end
|
11
29
|
|
12
30
|
def self.for(nested_sanitizer_klass, value, options)
|
13
31
|
if value.nil? && options[:allow_nil] && !options[:collection]
|
14
32
|
NilAllowed.new
|
33
|
+
elsif !value.is_a?(Hash)
|
34
|
+
HashExpected.new(value)
|
15
35
|
else
|
16
36
|
nested_sanitizer_klass.new(value, options)
|
17
37
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -484,6 +484,11 @@ describe InputSanitizer::V2::PayloadSanitizer do
|
|
484
484
|
end
|
485
485
|
|
486
486
|
describe "array of nested objects" do
|
487
|
+
it "is valid when given a collection of nested objects" do
|
488
|
+
@params = { :tags => [{:id => 1, :name => "crm", :addresses => []}]}
|
489
|
+
sanitizer.should be_valid
|
490
|
+
end
|
491
|
+
|
487
492
|
it "returns an error when given a nil for a collection" do
|
488
493
|
@params = { :tags => nil }
|
489
494
|
sanitizer.should_not be_valid
|
@@ -494,6 +499,13 @@ describe InputSanitizer::V2::PayloadSanitizer do
|
|
494
499
|
sanitizer.should_not be_valid
|
495
500
|
end
|
496
501
|
|
502
|
+
it "returns an error when given an collection of raw values" do
|
503
|
+
@params = { :tags => ['nope'] }
|
504
|
+
sanitizer.should_not be_valid
|
505
|
+
sanitizer.errors.length.should eq(1)
|
506
|
+
sanitizer.errors.map(&:field).should contain_exactly('/tags/0')
|
507
|
+
end
|
508
|
+
|
497
509
|
it "returns an error when given a hash for a collection" do
|
498
510
|
@params = { :tags => { :a => 1 } }
|
499
511
|
sanitizer.should_not be_valid
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: input_sanitizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zendesk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: method_struct
|