stronger_parameters 2.22.0 → 2.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/stronger_parameters/constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/array_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/boolean_constraint.rb +4 -3
- data/lib/stronger_parameters/constraints/comparison_constraints.rb +2 -1
- data/lib/stronger_parameters/constraints/date_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/date_iso8601_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/date_time_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/decimal_constraint.rb +3 -2
- data/lib/stronger_parameters/constraints/enumeration_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/file_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/float_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/hash_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/hex_constraint.rb +3 -2
- data/lib/stronger_parameters/constraints/integer_constraint.rb +3 -2
- data/lib/stronger_parameters/constraints/nil_constraint.rb +3 -2
- data/lib/stronger_parameters/constraints/nil_string_constraint.rb +3 -2
- data/lib/stronger_parameters/constraints/regexp_constraint.rb +3 -2
- data/lib/stronger_parameters/constraints/string_constraint.rb +4 -3
- data/lib/stronger_parameters/constraints/time_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/time_iso8601_constraint.rb +2 -1
- data/lib/stronger_parameters/constraints/ulid_constraint.rb +4 -3
- data/lib/stronger_parameters/constraints.rb +23 -22
- data/lib/stronger_parameters/controller_support/permitted_parameters.rb +4 -3
- data/lib/stronger_parameters/errors.rb +1 -0
- data/lib/stronger_parameters/parameters.rb +12 -11
- data/lib/stronger_parameters/version.rb +2 -1
- data/lib/stronger_parameters.rb +6 -5
- metadata +8 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5455cd0a895d92a75b2233ca7c0c354daa175fe5f87b0e93c2a3c70841a6d5ba
|
4
|
+
data.tar.gz: 44a29a9c69fc1e9e8b601d9fbf9298d3c53620d349cdd552d53e195ed993a91e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b73b50ec00b778044f198c5e6983fc0e8e059cee0528feabd1bd8a8a4baecd0210d2ca9f8363392d7c5db2c650605df2d24b3abe881deac8a1b910ee42c4540
|
7
|
+
data.tar.gz: 00e7adc12e37a1a3d6179a92433af706706f5c0a75dacf87811a9a1a547985fed4c4542e01d87a567657a1f03a87916f4eae6cd13bb298e62dbf344002f89439
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# stronger_parameters
|
2
|
-
![CI](https://github.com/zendesk/stronger_parameters/workflows/
|
2
|
+
[![CI status](https://github.com/zendesk/stronger_parameters/actions/workflows/actions.yml/badge.svg?branch=master)](https://github.com/zendesk/stronger_parameters/actions/workflows/actions.yml?query=branch%3Amaster)
|
3
3
|
|
4
4
|
This is an extension of `strong_parameters` with added type checking and conversion.
|
5
5
|
|
@@ -285,4 +285,5 @@ git commit -a --amend --no-edit
|
|
285
285
|
bundle exec rake release
|
286
286
|
```
|
287
287
|
|
288
|
-
[github action](.github/workflows/ruby-gem-publication.yml) will release a new version to rubygems.org
|
288
|
+
- [github action](.github/workflows/ruby-gem-publication.yml) will release a new version to rubygems.org
|
289
|
+
- approve the new version [here](https://github.com/zendesk/stronger_parameters/actions/workflows/ruby-gem-publication.yml)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class BooleanConstraint < Constraint
|
6
|
-
TRUE_VALUES
|
7
|
-
FALSE_VALUES = [false,
|
7
|
+
TRUE_VALUES = [true, "true", "1", 1, "on"].freeze
|
8
|
+
FALSE_VALUES = [false, "false", "0", 0].freeze
|
8
9
|
|
9
10
|
def value(v)
|
10
11
|
v = v.downcase if v.is_a? String
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class DecimalConstraint < Constraint
|
@@ -11,7 +12,7 @@ module StrongerParameters
|
|
11
12
|
|
12
13
|
def value(v)
|
13
14
|
match = v.to_s
|
14
|
-
if match
|
15
|
+
if match&.match?(@regex)
|
15
16
|
BigDecimal(match)
|
16
17
|
else
|
17
18
|
StrongerParameters::InvalidValue.new(v, "must be a decimal with precision #{@precision} and scale #{@scale}")
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class HexConstraint < Constraint
|
6
7
|
def value(v)
|
7
8
|
return v if v.is_a?(String) && v.match?(/\A[a-f0-9]+\z/i)
|
8
9
|
|
9
|
-
InvalidValue.new(v,
|
10
|
+
InvalidValue.new(v, "must be a hexadecimal string")
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class IntegerConstraint < Constraint
|
@@ -10,7 +11,7 @@ module StrongerParameters
|
|
10
11
|
return v.to_i
|
11
12
|
end
|
12
13
|
|
13
|
-
InvalidValue.new(v,
|
14
|
+
InvalidValue.new(v, "must be an integer")
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class NilConstraint < Constraint
|
6
7
|
def value(v)
|
7
8
|
return v if v.nil?
|
8
9
|
|
9
|
-
InvalidValue.new(v,
|
10
|
+
InvalidValue.new(v, "must be an nil")
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class NilStringConstraint < Constraint
|
6
|
-
NULL_VALUES = [nil,
|
7
|
+
NULL_VALUES = [nil, "", "undefined"].freeze
|
7
8
|
|
8
9
|
def value(v)
|
9
10
|
if NULL_VALUES.include?(v)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class RegexpConstraint < Constraint
|
@@ -14,7 +15,7 @@ module StrongerParameters
|
|
14
15
|
v = @string.value(v)
|
15
16
|
return v if v.is_a?(InvalidValue)
|
16
17
|
|
17
|
-
if v
|
18
|
+
if v&.match?(regexp)
|
18
19
|
v
|
19
20
|
else
|
20
21
|
InvalidValue.new(v, "must match #{regexp.source}")
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class StringConstraint < Constraint
|
@@ -17,13 +18,13 @@ module StrongerParameters
|
|
17
18
|
elsif minimum_length && v.bytesize < minimum_length
|
18
19
|
return InvalidValue.new(v, "can not be shorter than #{minimum_length} bytes")
|
19
20
|
elsif !v.valid_encoding?
|
20
|
-
return InvalidValue.new(v,
|
21
|
+
return InvalidValue.new(v, "must have valid encoding")
|
21
22
|
end
|
22
23
|
|
23
24
|
return v
|
24
25
|
end
|
25
26
|
|
26
|
-
InvalidValue.new(v,
|
27
|
+
InvalidValue.new(v, "must be a string")
|
27
28
|
end
|
28
29
|
|
29
30
|
def ==(other)
|
@@ -1,16 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
class UlidConstraint < Constraint
|
6
7
|
# https://www.crockford.com/base32.html
|
7
|
-
INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i
|
8
|
+
INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i
|
8
9
|
ULID_LENGTH = 26
|
9
10
|
|
10
11
|
def value(v)
|
11
12
|
return invalid_value(v) unless v.is_a?(String)
|
12
13
|
return invalid_value(v) unless v.length == ULID_LENGTH
|
13
|
-
return invalid_value(v) if v
|
14
|
+
return invalid_value(v) if INVALID_CHAR_REGEX.match?(v)
|
14
15
|
|
15
16
|
v
|
16
17
|
end
|
@@ -1,23 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
2
|
+
|
3
|
+
require "stronger_parameters/constraint"
|
4
|
+
require "stronger_parameters/constraints/string_constraint"
|
5
|
+
require "stronger_parameters/constraints/float_constraint"
|
6
|
+
require "stronger_parameters/constraints/date_constraint"
|
7
|
+
require "stronger_parameters/constraints/date_iso8601_constraint"
|
8
|
+
require "stronger_parameters/constraints/time_constraint"
|
9
|
+
require "stronger_parameters/constraints/time_iso8601_constraint"
|
10
|
+
require "stronger_parameters/constraints/date_time_constraint"
|
11
|
+
require "stronger_parameters/constraints/date_time_iso8601_constraint"
|
12
|
+
require "stronger_parameters/constraints/regexp_constraint"
|
13
|
+
require "stronger_parameters/constraints/integer_constraint"
|
14
|
+
require "stronger_parameters/constraints/nil_constraint"
|
15
|
+
require "stronger_parameters/constraints/boolean_constraint"
|
16
|
+
require "stronger_parameters/constraints/array_constraint"
|
17
|
+
require "stronger_parameters/constraints/hash_constraint"
|
18
|
+
require "stronger_parameters/constraints/enumeration_constraint"
|
19
|
+
require "stronger_parameters/constraints/comparison_constraints"
|
20
|
+
require "stronger_parameters/constraints/nil_string_constraint"
|
21
|
+
require "stronger_parameters/constraints/file_constraint"
|
22
|
+
require "stronger_parameters/constraints/decimal_constraint"
|
23
|
+
require "stronger_parameters/constraints/hex_constraint"
|
24
|
+
require "stronger_parameters/constraints/ulid_constraint"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "stronger_parameters/constraints"
|
3
4
|
|
4
5
|
module StrongerParameters
|
5
6
|
module ControllerSupport
|
@@ -50,7 +51,7 @@ module StrongerParameters
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def permitted_parameters_for(action)
|
53
|
-
unless for_action = permit_parameters[action]
|
54
|
+
unless (for_action = permit_parameters[action])
|
54
55
|
# NOTE: there is no easy way to test this, so make sure to test with
|
55
56
|
# a real rails controller if you make changes.
|
56
57
|
message = "Action #{action} for #{self} does not have any permitted parameters"
|
@@ -101,7 +102,7 @@ module StrongerParameters
|
|
101
102
|
def show_unpermitted_keys(unpermitted_keys, log_unpermitted)
|
102
103
|
return if unpermitted_keys.empty?
|
103
104
|
|
104
|
-
log_prefix = (log_unpermitted ?
|
105
|
+
log_prefix = (log_unpermitted ? "Found" : "Removed")
|
105
106
|
message =
|
106
107
|
"#{log_prefix} restricted keys #{unpermitted_keys.inspect} from parameters according to permitted list"
|
107
108
|
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'action_pack'
|
3
2
|
|
4
|
-
require
|
5
|
-
require 'action_controller/api'
|
6
|
-
require 'action_controller/metal/strong_parameters'
|
3
|
+
require "action_pack"
|
7
4
|
|
8
|
-
require
|
9
|
-
require
|
5
|
+
require "action_controller/base"
|
6
|
+
require "action_controller/api"
|
7
|
+
require "action_controller/metal/strong_parameters"
|
8
|
+
|
9
|
+
require "stronger_parameters/constraints"
|
10
|
+
require "stronger_parameters/errors"
|
10
11
|
|
11
12
|
module StrongerParameters
|
12
13
|
module Parameters
|
@@ -83,7 +84,7 @@ module StrongerParameters
|
|
83
84
|
def enumeration(*allowed)
|
84
85
|
EnumerationConstraint.new(*allowed)
|
85
86
|
end
|
86
|
-
|
87
|
+
alias_method :enum, :enumeration
|
87
88
|
|
88
89
|
def boolean
|
89
90
|
BooleanConstraint.new
|
@@ -148,7 +149,7 @@ module StrongerParameters
|
|
148
149
|
|
149
150
|
def hash_filter_with_stronger_parameters(params, filter)
|
150
151
|
stronger_filter = ActiveSupport::HashWithIndifferentAccess.new
|
151
|
-
other_filter
|
152
|
+
other_filter = ActiveSupport::HashWithIndifferentAccess.new
|
152
153
|
|
153
154
|
filter.each do |k, v|
|
154
155
|
if v.is_a?(Constraint)
|
@@ -173,7 +174,7 @@ module StrongerParameters
|
|
173
174
|
if key?(key)
|
174
175
|
result = constraint.value(value)
|
175
176
|
elsif constraint.required?
|
176
|
-
result = InvalidValue.new(nil,
|
177
|
+
result = InvalidValue.new(nil, "must be present")
|
177
178
|
else
|
178
179
|
next # uncovered
|
179
180
|
end
|
@@ -211,8 +212,8 @@ module StrongerParameters
|
|
211
212
|
# TODO: this is not consistent with the behavior of raising ActionController::UnpermittedParameters
|
212
213
|
# should have the same render vs raise behavior in test/dev ... see permitted_parameters_test.rb
|
213
214
|
rescue_from(StrongerParameters::InvalidParameter) do |e|
|
214
|
-
if request.format.to_s.include?(
|
215
|
-
render json: {
|
215
|
+
if request.format.to_s.include?("json")
|
216
|
+
render json: {error: e.message}, status: :bad_request
|
216
217
|
else
|
217
218
|
render plain: e.message, status: :bad_request
|
218
219
|
end
|
data/lib/stronger_parameters.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
2
|
+
|
3
|
+
require "stronger_parameters/version"
|
4
|
+
require "action_pack"
|
5
|
+
require "stronger_parameters/parameters"
|
6
|
+
require "stronger_parameters/constraints"
|
7
|
+
require "stronger_parameters/controller_support/permitted_parameters"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stronger_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mick Staugaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: standard
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -129,9 +129,6 @@ dependencies:
|
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '5.0'
|
132
|
-
- - "<"
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: '7.2'
|
135
132
|
type: :runtime
|
136
133
|
prerelease: false
|
137
134
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -139,9 +136,6 @@ dependencies:
|
|
139
136
|
- - ">="
|
140
137
|
- !ruby/object:Gem::Version
|
141
138
|
version: '5.0'
|
142
|
-
- - "<"
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '7.2'
|
145
139
|
description:
|
146
140
|
email:
|
147
141
|
- mick@zendesk.com
|
@@ -198,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
192
|
- !ruby/object:Gem::Version
|
199
193
|
version: '0'
|
200
194
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
195
|
+
rubygems_version: 3.5.11
|
202
196
|
signing_key:
|
203
197
|
specification_version: 4
|
204
198
|
summary: Type checking and type casting of parameters for Action Pack
|