input_sanitizer 0.4.1 → 0.6.0

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: 4f2a20c5da1c65b87f1e817d27093de8f9353a6c06b542780d27e3462b64a855
4
- data.tar.gz: d48d86aac58840dfc42932c1240635552bc3229d297d8f717615088582e6b31c
3
+ metadata.gz: 42f76190c3f31a2a1cd2a3372fcda7bad0e107b621ec3f34cc46ef5a1724b08e
4
+ data.tar.gz: 4b4400b8f4305308dd076f3a9092a9606fe48860809fadda7a2029cf8fcb57fb
5
5
  SHA512:
6
- metadata.gz: 3dcfbf917beba6d666b964658b8ef569152d74beca656f14640fec37a9bc413273da22988e4eeebfe4aa399841086673519bb3a1eb8c6533d0ada93ac474021b
7
- data.tar.gz: 56cb28724e2cfbd5eb1755615463e26226cca48ba287d3ee94448da1f5918261d4a8aa430a4b14e82b9bbc6d2fa96888799ecc144ccf6ee585fece7709eee5e1
6
+ metadata.gz: b5c9fcd7ff42c69d76fe7c266972e12e18a50bd09a325ef8b3dd02321f205a8596c4eab2ac5e8eea4b42a4761198a0f6d7ecdfeb9b052764dfb99d048698c43b
7
+ data.tar.gz: 8137f9b0b246eb3fdbf74d828bab6f3d97fe5c79616eac19821f727bf0229e277e7d6056bbef2836fd1658dc2766955a95786cf9645d927339a81039028661d2
@@ -1,26 +1,27 @@
1
1
  name: CI
2
2
 
3
- on:
4
- push:
5
- branches:
6
- - master
7
- pull_request:
8
- branches:
9
- - master
3
+ on: push
10
4
 
11
5
  jobs:
12
6
  build:
13
- runs-on: ubuntu-18.04
7
+ runs-on: ubuntu-latest
14
8
  strategy:
15
9
  matrix:
16
- rvm: [2.1.9,2.2.10,2.5.8,jruby-head]
10
+ ruby-version:
11
+ - 2.3.8
12
+ - 2.5.8
13
+ - 2.6.8
14
+ - 2.7.6
15
+ - 3.0.4
16
+ - 3.1.2
17
+ - 3.2.0
17
18
  steps:
18
- - uses: zendesk/checkout@v2
19
+ - uses: zendesk/checkout@v3
19
20
  - name: Set up Ruby
20
21
  uses: zendesk/setup-ruby@v1
21
22
  with:
22
- ruby-version: ${{ matrix.rvm }}
23
- - name: Test ${{ matrix.rvm }}
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ - name: Test ${{ matrix.ruby-version }}
24
25
  run: |
25
26
  bundle install
26
27
  bundle exec rspec spec
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/version_tmp
17
17
  tmp
18
18
  /bin
19
19
  Gemfile.lock
20
+ /out
21
+ *iml
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.6.0
2
+ * Validate array of hashes is passed to collection of nested objects
3
+
4
+ 0.5.0
5
+ * Added support for Ruby 3
6
+
1
7
  0.4.1
2
8
  * Added `strip_4byte_chars` option to String V2 sanitizer
3
9
 
@@ -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
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/object/blank'
2
+ require 'uri'
2
3
 
3
4
  module InputSanitizer::V2::Types
4
5
  class IntegerCheck
@@ -1,3 +1,3 @@
1
1
  module InputSanitizer
2
- VERSION = "0.4.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -19,4 +19,3 @@ RSpec.configure do |config|
19
19
  end
20
20
 
21
21
  require 'input_sanitizer'
22
- require 'pry'
@@ -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.1
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: 2021-05-17 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_struct