validate-params 0.12.5 → 0.13.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/CHANGELOG.md +19 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -5
- data/docker-compose.yml +1 -0
- data/lib/validate_params/configuration.rb +17 -0
- data/lib/validate_params/extenstions/string.rb +7 -0
- data/lib/validate_params/param_builder.rb +1 -0
- data/lib/validate_params/param_validator.rb +1 -0
- data/lib/validate_params/types/string.rb +10 -2
- data/lib/validate_params/utilities/scrubber.rb +13 -0
- data/lib/validate_params/validatable.rb +10 -0
- data/lib/validate_params/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77ee095dc2316a90b3784532a9d0586777c187b99c63b489129e4c0d6c4c6b2b
|
4
|
+
data.tar.gz: 17f55ad85601e32c1218f76c0b3e804b83cd5159b41308c0a448431f7a360dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6b277ff7d5d03c8926a9ccf3b6b730bed2527de0e70d44fdc1853e749c6701a0072d39aa3e1679be0a22ae93d72569cff7986ff1b71f1d424c80f2b3831c1e
|
7
|
+
data.tar.gz: a5001cd005f065d12ffaa16a6f0f97b1148bf5934ea37e2804d6c5b749f7b666116fdb6b060a49babfa84b354dd3f4ce1685e73bd2f56670dcf579338cb1ae42
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.13.0] - 2024-04-16
|
2
|
+
|
3
|
+
- Added `:scrub_invalid_utf8` and `:scrub_invalid_utf8_replacement` options to String type to handle invalid UTF-8 characters
|
4
|
+
- Added [configurator](README.md#configuration) to change default behaviour for certain options
|
5
|
+
|
6
|
+
|
1
7
|
## [0.12.5] - 2024-04-15
|
2
8
|
|
3
9
|
- Restrict validation rules for Hash type objects
|
@@ -10,6 +16,19 @@
|
|
10
16
|
|
11
17
|
- Default option for Integer type should support empty string as well
|
12
18
|
|
19
|
+
## [0.12.2] - 2024-03-11
|
20
|
+
|
21
|
+
- Added inheritance of validate params rule between child and parent controllers
|
22
|
+
|
23
|
+
## [0.12.1] - 2024-03-05
|
24
|
+
|
25
|
+
- Fixed support of ActionController::Parameters along with Hash
|
26
|
+
|
27
|
+
## [0.12.0] - 2024-03-05
|
28
|
+
|
29
|
+
- Added support of array of hashes
|
30
|
+
- Improved nested attributes validation
|
31
|
+
|
13
32
|
## [0.11.0] - 2023-11-04
|
14
33
|
|
15
34
|
- Added support for Float type
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,11 +8,28 @@ ValidateParams is a lightweight, robust Ruby on Rails gem that introduces a simp
|
|
8
8
|
|
9
9
|
Install the gem and add to the application's Gemfile by executing:
|
10
10
|
|
11
|
-
$ bundle add
|
11
|
+
$ bundle add validate-params
|
12
12
|
|
13
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
14
|
|
15
|
-
$ gem install
|
15
|
+
$ gem install validate-params
|
16
|
+
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
To configure default options, create `config/initializers/validate_params.rb` file. Configuration example:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Rails.application.config.after_initialize do
|
24
|
+
ValidateParams::Validatable.configure do |config|
|
25
|
+
config.scrub_invalid_utf8 = true # Default: false
|
26
|
+
config.scrub_invalid_utf8_replacement = "�" # Default: empty string
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
30
|
+
Currently only these options are supported in configuration. If you need more options, please create an issue.
|
31
|
+
|
32
|
+
**Be aware**: `scrub_invalid_utf8` mutates parameters value passed into controller. Learn more in [params mutation](#params-mutation) section.
|
16
33
|
|
17
34
|
## Usage
|
18
35
|
|
@@ -51,7 +68,7 @@ end
|
|
51
68
|
|
52
69
|
Here are the following supported types along with operations supported.
|
53
70
|
|
54
|
-
- String (required, default)
|
71
|
+
- String (required, default, scrub_invalid_utf8, scrub_invalid_utf8_replacement)
|
55
72
|
- Integer (required, default, min, max, in)
|
56
73
|
- Float (required, default, min, max, in)
|
57
74
|
- Date (required, default, min, max)
|
@@ -61,6 +78,14 @@ Here are the following supported types along with operations supported.
|
|
61
78
|
- Hash - Nested block of types
|
62
79
|
|
63
80
|
|
81
|
+
### Params mutation
|
82
|
+
|
83
|
+
String type supports `scrub_invalid_utf8` and `scrub_invalid_utf8_replacement` options to handle invalid UTF-8 characters.
|
84
|
+
If `scrub_invalid_utf8` is set to true, it will replace invalid UTF-8 characters with the value of `scrub_invalid_utf8_replacement`.
|
85
|
+
|
86
|
+
This modified value will be passed to the controller parameters.
|
87
|
+
|
88
|
+
|
64
89
|
## Response
|
65
90
|
|
66
91
|
If the parameters are valid, the controller action will be executed as normal. If the parameters are invalid, a **400 Bad Request** response will be returned with a JSON body containing the errors, or an empty HTML response.
|
@@ -81,8 +106,7 @@ If the parameters are valid, the controller action will be executed as normal. I
|
|
81
106
|
{
|
82
107
|
"message": "states is an invalid value",
|
83
108
|
"valid_values": ["active", "inactive"]
|
84
|
-
}
|
85
|
-
|
109
|
+
}
|
86
110
|
]
|
87
111
|
}
|
88
112
|
```
|
data/docker-compose.yml
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module ValidateParams
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :scrub_invalid_utf8, :scrub_invalid_utf8_replacement
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@scrub_invalid_utf8 = false
|
7
|
+
@scrub_invalid_utf8_replacement = ""
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_h
|
11
|
+
{
|
12
|
+
scrub_invalid_utf8: scrub_invalid_utf8,
|
13
|
+
scrub_invalid_utf8_replacement: scrub_invalid_utf8_replacement,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,10 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "validate_params/utilities/scrubber"
|
4
|
+
|
3
5
|
module ValidateParams
|
4
6
|
class Types
|
5
7
|
class String
|
6
|
-
def self.cast(raw_value, **)
|
7
|
-
raw_value.to_s
|
8
|
+
def self.cast(raw_value, scrub_invalid_utf8: false, **)
|
9
|
+
value = raw_value.to_s
|
10
|
+
|
11
|
+
if scrub_invalid_utf8
|
12
|
+
value = Validatable::Utilities::Scrubber.scrub(raw_value)
|
13
|
+
end
|
14
|
+
|
15
|
+
value
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ValidateParams
|
2
|
+
module Validatable
|
3
|
+
module Utilities
|
4
|
+
class Scrubber
|
5
|
+
def self.scrub(input_string, replacement: Validatable.configuration.scrub_invalid_utf8_replacement)
|
6
|
+
input_string
|
7
|
+
.scrub(replacement)
|
8
|
+
.tr("\u0000", replacement)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "validate_params/configuration"
|
4
|
+
|
3
5
|
require "validate_params/types/date"
|
4
6
|
require "validate_params/types/date_time"
|
5
7
|
require "validate_params/types/integer"
|
@@ -16,6 +18,14 @@ module ValidateParams
|
|
16
18
|
module Validatable
|
17
19
|
extend ::ActiveSupport::Concern
|
18
20
|
|
21
|
+
def self.configure
|
22
|
+
yield(configuration)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configuration
|
26
|
+
@configuration ||= Configuration.new
|
27
|
+
end
|
28
|
+
|
19
29
|
included do
|
20
30
|
before_action :perform_validate_params
|
21
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate-params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dcherevatenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -111,6 +111,8 @@ files:
|
|
111
111
|
- config/locales/en.yml
|
112
112
|
- docker-compose.yml
|
113
113
|
- lib/validate_params.rb
|
114
|
+
- lib/validate_params/configuration.rb
|
115
|
+
- lib/validate_params/extenstions/string.rb
|
114
116
|
- lib/validate_params/param_builder.rb
|
115
117
|
- lib/validate_params/param_validator.rb
|
116
118
|
- lib/validate_params/types/array.rb
|
@@ -120,6 +122,7 @@ files:
|
|
120
122
|
- lib/validate_params/types/i_o.rb
|
121
123
|
- lib/validate_params/types/integer.rb
|
122
124
|
- lib/validate_params/types/string.rb
|
125
|
+
- lib/validate_params/utilities/scrubber.rb
|
123
126
|
- lib/validate_params/validatable.rb
|
124
127
|
- lib/validate_params/version.rb
|
125
128
|
- sig/validate_params.rbs
|