ac-sanitizer 3.9.18 → 3.10.2
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.
- package/CHANGELOG.md +35 -0
- package/README.md +1 -0
- package/index.js +52 -18
- package/package.json +1 -1
- package/test/suites/default.js +5 -0
- package/test/tests/any.js +49 -0
- package/test/tests/array.js +1 -1
- package/test/tests/base64.js +1 -1
- package/test/tests/bool.js +1 -1
- package/test/tests/boolOrInteger.js +1 -1
- package/test/tests/cidr.js +1 -1
- package/test/tests/country.js +1 -1
- package/test/tests/date.js +1 -1
- package/test/tests/email.js +1 -1
- package/test/tests/error.js +3 -2
- package/test/tests/fileExtension.js +1 -1
- package/test/tests/fqdn.js +1 -1
- package/test/tests/gps.js +1 -1
- package/test/tests/hashIds.js +1 -1
- package/test/tests/hexColor.js +1 -1
- package/test/tests/index.js +1 -0
- package/test/tests/ip.js +1 -1
- package/test/tests/number.js +2 -1
- package/test/tests/object.js +1 -1
- package/test/tests/ratio.js +1 -1
- package/test/tests/rgb.js +1 -1
- package/test/tests/string.js +1 -1
- package/test/tests/stringOrInteger.js +2 -2
- package/test/tests/url.js +1 -1
- package/test/tests/uuid.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
<a name="3.10.2"></a>
|
|
2
|
+
|
|
3
|
+
## [3.10.2](https://github.com/mmpro/ac-sanitizer/compare/v3.10.1..v3.10.2) (2022-04-28 11:21:08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fix
|
|
7
|
+
|
|
8
|
+
* **App:** Detect int and float | MP | [1320003ec27cb1b85824aa0ad719b2d23b4ef5e5](https://github.com/mmpro/ac-sanitizer/commit/1320003ec27cb1b85824aa0ad719b2d23b4ef5e5)
|
|
9
|
+
Detect int and float
|
|
10
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
11
|
+
<a name="3.10.1"></a>
|
|
12
|
+
|
|
13
|
+
## [3.10.1](https://github.com/mmpro/ac-sanitizer/compare/v3.10.0..v3.10.1) (2022-04-24 19:38:16)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fix
|
|
17
|
+
|
|
18
|
+
* **App:** Fix for checking float | MP | [bd68b7c8bd76d15d22d9d2dea8ce78e07be7d3c9](https://github.com/mmpro/ac-sanitizer/commit/bd68b7c8bd76d15d22d9d2dea8ce78e07be7d3c9)
|
|
19
|
+
Check if type float is really a float
|
|
20
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
21
|
+
### Tests
|
|
22
|
+
|
|
23
|
+
* **App:** Fixed tests | MP | [96e8d6067c219a241840e253ac9e11c36b258df0](https://github.com/mmpro/ac-sanitizer/commit/96e8d6067c219a241840e253ac9e11c36b258df0)
|
|
24
|
+
Make sure to check for errors from function
|
|
25
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
26
|
+
<a name="3.10.0"></a>
|
|
27
|
+
|
|
28
|
+
# [3.10.0](https://github.com/mmpro/ac-sanitizer/compare/v3.9.18..v3.10.0) (2022-04-24 18:45:04)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Feature
|
|
32
|
+
|
|
33
|
+
* **App:** Add type any | MP | [ff0858e978b7f7195f68ad5c9c346723107075fb](https://github.com/mmpro/ac-sanitizer/commit/ff0858e978b7f7195f68ad5c9c346723107075fb)
|
|
34
|
+
Type any will try to determine the actual type but gives you flexibility while sanitizing.
|
|
35
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
1
36
|
<a name="3.9.18"></a>
|
|
2
37
|
|
|
3
38
|
## [3.9.18](https://github.com/mmpro/ac-sanitizer/compare/v3.9.17..v3.9.18) (2022-04-24 18:09:53)
|
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ countrylist | list of country names | e.g. Laos, Brazil, Norway...
|
|
|
69
69
|
|
|
70
70
|
Type | Options | Remarks
|
|
71
71
|
--- | --- | --- |
|
|
72
|
+
any | | Any can be string, integer, boolean, object or array - it will be automatically detected.
|
|
72
73
|
base64 | | Checks if a string is base64 encoded, optional with field option "convert" (to string)
|
|
73
74
|
boolean | |
|
|
74
75
|
cidr | | Check CIDR, see example
|
package/index.js
CHANGED
|
@@ -116,6 +116,31 @@ const sanitizer = function() {
|
|
|
116
116
|
|
|
117
117
|
if (!error && _.has(paramsToCheck, fieldName)) {
|
|
118
118
|
/// SPECIAL FIELDS
|
|
119
|
+
// field type any, can be any field
|
|
120
|
+
if (field.type === 'any') {
|
|
121
|
+
if (_.isString(value)) {
|
|
122
|
+
field.type = 'string'
|
|
123
|
+
}
|
|
124
|
+
else if (_.isPlainObject(value)) {
|
|
125
|
+
field.type = 'object'
|
|
126
|
+
}
|
|
127
|
+
else if (_.isArray(value)) {
|
|
128
|
+
field.type = 'array'
|
|
129
|
+
}
|
|
130
|
+
else if (_.isBoolean(value)) {
|
|
131
|
+
field.type = 'boolean'
|
|
132
|
+
}
|
|
133
|
+
else if (_.isInteger(value)) {
|
|
134
|
+
field.type = 'integer'
|
|
135
|
+
}
|
|
136
|
+
else if (_.isFinite(value)) {
|
|
137
|
+
field.type = 'float'
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
error = { message: fieldName + '_couldNotResolveType' }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
119
144
|
// special field - can be string or integer -> determine type and then use type settings
|
|
120
145
|
if (field.type === 'integer | string') {
|
|
121
146
|
if (!_.isString(value) && !_.isFinite(parseInt(value))) {
|
|
@@ -170,27 +195,36 @@ const sanitizer = function() {
|
|
|
170
195
|
}
|
|
171
196
|
else if (_.indexOf(['number', 'integer', 'long', 'short', 'float'], field.type) > -1) {
|
|
172
197
|
if (typeof value != 'number' || isNaN(value)) error = { message: fieldName + '_' + getTypeMapping('integer', 'errorMessage') }
|
|
198
|
+
else {
|
|
199
|
+
// Number types - usually we allow only non-negative values (unsigned). If you want negative values, set type.subtype 'signed'
|
|
200
|
+
if (field.type === 'number') console.error('SANITIZER - number should not be used, be more precise')
|
|
201
|
+
if (field.type === 'number') field.type = 'integer'
|
|
173
202
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
203
|
+
if (field.type === 'float' && value !== parseFloat(value)) {
|
|
204
|
+
error = { message: fieldName + '_not_' + field.type, additionalInfo: { value } }
|
|
205
|
+
}
|
|
206
|
+
else if (field.type !== 'float' && value !== parseInt(value)) {
|
|
207
|
+
error = { message: fieldName + '_typeIncorrect', additionalInfo: { value, int: parseInt(value) } }
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const subtype = _.get(field, 'subtype')
|
|
211
|
+
let ranges = {
|
|
212
|
+
integer: [(subtype === 'signed' ? -Math.pow(2, 31) : 0), Math.pow(2, 31)],
|
|
213
|
+
long: [(subtype === 'signed' ? -(Math.pow(2,53) - 1) : 0), Math.pow(2, 53)-1],
|
|
214
|
+
short: [(subtype === 'signed' ? -Math.pow(2, 15) : 0), Math.pow(2, 15)],
|
|
215
|
+
float: [(subtype === 'signed' ? -Math.pow(2, 31) : 0), Math.pow(2, 31)]
|
|
216
|
+
}
|
|
217
|
+
let range = _.get(field, 'range', _.get(ranges, field.type, ranges.integer))
|
|
186
218
|
|
|
187
|
-
|
|
188
|
-
|
|
219
|
+
if (field.type === 'float') value = parseFloat(value)
|
|
220
|
+
else value = parseInt(value)
|
|
189
221
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
222
|
+
let lowest = _.first(range)
|
|
223
|
+
let highest = _.size(range) === 2 && _.last(range)
|
|
224
|
+
if (value < lowest || (highest && value > highest)) {
|
|
225
|
+
error = { message: fieldName + '_outOfRange', additionalInfo: { range, value } }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
194
228
|
}
|
|
195
229
|
}
|
|
196
230
|
else if (field.type === 'string') {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "admiralcloud/ac-sanitizer",
|
|
7
|
-
"version": "3.
|
|
7
|
+
"version": "3.10.2",
|
|
8
8
|
"homepage": "https://www.admiralcloud.com",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"ac-countrylist": "^1.0.6",
|
package/test/suites/default.js
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
const expect = require('expect')
|
|
3
|
+
const sanitizer = require('../../index')
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
|
|
7
|
+
test: () => {
|
|
8
|
+
|
|
9
|
+
const baseTests = [
|
|
10
|
+
{ name: 'Any - with string', type: 'any', value: 'admiralcloud', expected: 'admiralcloud' },
|
|
11
|
+
{ name: 'Any - with integer', type: 'any', value: 123, expected: 123 },
|
|
12
|
+
{ name: 'Any - with boolean', type: 'any', value: true, expected: true },
|
|
13
|
+
{ name: 'Any - with boolean - false', type: 'any', value: false, expected: false },
|
|
14
|
+
{ name: 'Any - with object', type: 'any', value: { a: 123 }, expected: { a: 123 } },
|
|
15
|
+
{ name: 'Any - with array', type: 'any', value: [1,2,3], expected: [1,2,3] },
|
|
16
|
+
{ name: 'Any - with array of objects', type: 'any', value: [{ a: 123 }], expected: [{ a: 123 }] },
|
|
17
|
+
{ name: 'Any - with float', type: 'any', value: 123.235, expected: 123.235 },
|
|
18
|
+
{ name: 'Any - with Infinity - should fail', type: 'any', value: Infinity, error: 'any_couldNotResolveType' },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
_.forEach(baseTests, (test) => {
|
|
22
|
+
it(test.name, (done) => {
|
|
23
|
+
let fieldsToCheck = {
|
|
24
|
+
params: {
|
|
25
|
+
any: _.get(test, 'value')
|
|
26
|
+
},
|
|
27
|
+
fields: [
|
|
28
|
+
{ field: 'any', type: _.get(test, 'type') }
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
32
|
+
if (_.get(r, 'error')) {
|
|
33
|
+
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
34
|
+
if (_.get(test, 'additionalInfo')) {
|
|
35
|
+
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
expect(_.get(r, 'params.any')).toEqual(_.get(test, 'expected'))
|
|
40
|
+
}
|
|
41
|
+
return done()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
}
|
package/test/tests/array.js
CHANGED
|
@@ -50,7 +50,7 @@ module.exports = {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
53
|
-
if (_.get(
|
|
53
|
+
if (_.get(r, 'error')) {
|
|
54
54
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
55
55
|
if (_.get(test, 'additionalInfo')) {
|
|
56
56
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/base64.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
31
|
-
if (_.get(
|
|
31
|
+
if (_.get(r, 'error')) {
|
|
32
32
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
33
33
|
if (_.get(test, 'additionalInfo')) {
|
|
34
34
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/bool.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
31
|
-
if (_.get(
|
|
31
|
+
if (_.get(r, 'error')) {
|
|
32
32
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
33
33
|
if (_.get(test, 'additionalInfo')) {
|
|
34
34
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
|
@@ -24,7 +24,7 @@ module.exports = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
27
|
-
if (_.get(
|
|
27
|
+
if (_.get(r, 'error')) {
|
|
28
28
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
29
29
|
if (_.get(test, 'additionalInfo')) {
|
|
30
30
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/cidr.js
CHANGED
|
@@ -29,7 +29,7 @@ module.exports = {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
32
|
-
if (_.get(
|
|
32
|
+
if (_.get(r, 'error')) {
|
|
33
33
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
34
34
|
if (_.get(test, 'additionalInfo')) {
|
|
35
35
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/country.js
CHANGED
|
@@ -25,7 +25,7 @@ module.exports = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
28
|
-
if (_.get(
|
|
28
|
+
if (_.get(r, 'error')) {
|
|
29
29
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
30
30
|
if (_.get(test, 'additionalInfo')) {
|
|
31
31
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/date.js
CHANGED
|
@@ -31,7 +31,7 @@ module.exports = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
34
|
-
if (_.get(
|
|
34
|
+
if (_.get(r, 'error')) {
|
|
35
35
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
36
36
|
if (_.get(test, 'additionalInfo')) {
|
|
37
37
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/email.js
CHANGED
|
@@ -26,7 +26,7 @@ module.exports = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
29
|
-
if (_.get(
|
|
29
|
+
if (_.get(r, 'error')) {
|
|
30
30
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
31
31
|
if (_.get(test, 'additionalInfo')) {
|
|
32
32
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/error.js
CHANGED
|
@@ -17,16 +17,17 @@ module.exports = {
|
|
|
17
17
|
it(test.name, (done) => {
|
|
18
18
|
let fieldsToCheck = {
|
|
19
19
|
adminLevel: 4,
|
|
20
|
+
omitFields: _.get(test, 'omitFields'),
|
|
20
21
|
params: {
|
|
21
22
|
errorField: _.get(test, 'value'),
|
|
22
23
|
},
|
|
23
24
|
fields: [
|
|
24
|
-
{ field: 'errorField', type: _.get(test, 'type'), required: _.get(test, 'required'), adminLevel: _.get(test, 'adminLevel')
|
|
25
|
+
{ field: 'errorField', type: _.get(test, 'type'), required: _.get(test, 'required'), adminLevel: _.get(test, 'adminLevel') }
|
|
25
26
|
]
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
29
|
-
if (_.get(
|
|
30
|
+
if (_.get(r, 'error')) {
|
|
30
31
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
31
32
|
if (_.get(test, 'additionalInfo')) {
|
|
32
33
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
|
@@ -25,7 +25,7 @@ module.exports = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
28
|
-
if (_.get(
|
|
28
|
+
if (_.get(r, 'error')) {
|
|
29
29
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
30
30
|
if (_.get(test, 'additionalInfo')) {
|
|
31
31
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/fqdn.js
CHANGED
|
@@ -23,7 +23,7 @@ module.exports = {
|
|
|
23
23
|
]
|
|
24
24
|
}
|
|
25
25
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
26
|
-
if (_.get(
|
|
26
|
+
if (_.get(r, 'error')) {
|
|
27
27
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
28
28
|
if (_.get(test, 'additionalInfo')) {
|
|
29
29
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/gps.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
31
|
-
if (_.get(
|
|
31
|
+
if (_.get(r, 'error')) {
|
|
32
32
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
33
33
|
if (_.get(test, 'additionalInfo')) {
|
|
34
34
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/hashIds.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
31
|
-
if (_.get(
|
|
31
|
+
if (_.get(r, 'error')) {
|
|
32
32
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
33
33
|
if (_.get(test, 'additionalInfo')) {
|
|
34
34
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/hexColor.js
CHANGED
|
@@ -25,7 +25,7 @@ module.exports = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
28
|
-
if (_.get(
|
|
28
|
+
if (_.get(r, 'error')) {
|
|
29
29
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
30
30
|
if (_.get(test, 'additionalInfo')) {
|
|
31
31
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/index.js
CHANGED
package/test/tests/ip.js
CHANGED
|
@@ -26,7 +26,7 @@ module.exports = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
29
|
-
if (_.get(
|
|
29
|
+
if (_.get(r, 'error')) {
|
|
30
30
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
31
31
|
if (_.get(test, 'additionalInfo')) {
|
|
32
32
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/number.js
CHANGED
|
@@ -101,6 +101,7 @@ module.exports = {
|
|
|
101
101
|
{ name: 'Unsigned float -1 - should fail and display additionalInfo', type: 'float', value: -1, error: 'number_outOfRange', additionalInfo: { range: [0,2147483648], value: -1 } },
|
|
102
102
|
{ name: 'Array of numbers with one entry', type: 'integer', value: [123], error: 'number_notAFiniteNumber' },
|
|
103
103
|
{ name: 'Array of numbers with multiple entries', type: 'integer', value: [123, 456], error: 'number_notAFiniteNumber' },
|
|
104
|
+
{ name: 'Check float', type: 'float', range: [-90, 90], value: 53.15, expected: 53.15 }
|
|
104
105
|
]
|
|
105
106
|
|
|
106
107
|
_.forEach(tests, (test) => {
|
|
@@ -115,7 +116,7 @@ module.exports = {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
118
|
-
if (_.get(
|
|
119
|
+
if (_.get(r, 'error')) {
|
|
119
120
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
120
121
|
if (_.get(test, 'additionalInfo')) {
|
|
121
122
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/object.js
CHANGED
|
@@ -181,7 +181,7 @@ module.exports = {
|
|
|
181
181
|
],
|
|
182
182
|
};
|
|
183
183
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck);
|
|
184
|
-
if (_.get(
|
|
184
|
+
if (_.get(r, 'error')) {
|
|
185
185
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
186
186
|
if (_.get(test, 'additionalInfo')) {
|
|
187
187
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/ratio.js
CHANGED
|
@@ -26,7 +26,7 @@ module.exports = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
29
|
-
if (_.get(
|
|
29
|
+
if (_.get(r, 'error')) {
|
|
30
30
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
31
31
|
if (_.get(test, 'additionalInfo')) {
|
|
32
32
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/rgb.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
31
|
-
if (_.get(
|
|
31
|
+
if (_.get(r, 'error')) {
|
|
32
32
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
33
33
|
if (_.get(test, 'additionalInfo')) {
|
|
34
34
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/string.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
35
|
-
if (_.get(
|
|
35
|
+
if (_.get(r, 'error')) {
|
|
36
36
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
37
37
|
if (_.get(test, 'additionalInfo')) {
|
|
38
38
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
|
@@ -20,13 +20,13 @@ module.exports = {
|
|
|
20
20
|
let fieldsToCheck = {
|
|
21
21
|
params: {},
|
|
22
22
|
fields: [
|
|
23
|
-
{ field: 'stringOrInteger', type: _.get(test, 'type'), required: _.get(test, 'required') }
|
|
23
|
+
{ field: 'stringOrInteger', type: _.get(test, 'type'), required: _.get(test, 'required'), minLength: _.get(test, 'minLength') }
|
|
24
24
|
]
|
|
25
25
|
}
|
|
26
26
|
if (_.has(test, 'value')) fieldsToCheck.params.stringOrInteger = test.value
|
|
27
27
|
|
|
28
28
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
29
|
-
if (_.get(
|
|
29
|
+
if (_.get(r, 'error')) {
|
|
30
30
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
31
31
|
if (_.get(test, 'additionalInfo')) {
|
|
32
32
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/url.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
27
|
-
if (_.get(
|
|
27
|
+
if (_.get(r, 'error')) {
|
|
28
28
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
29
29
|
if (_.get(test, 'additionalInfo')) {
|
|
30
30
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|
package/test/tests/uuid.js
CHANGED
|
@@ -25,7 +25,7 @@ module.exports = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let r = sanitizer.checkAndSanitizeValues(fieldsToCheck)
|
|
28
|
-
if (_.get(
|
|
28
|
+
if (_.get(r, 'error')) {
|
|
29
29
|
expect(_.get(r, 'error.message')).toEqual(test.error)
|
|
30
30
|
if (_.get(test, 'additionalInfo')) {
|
|
31
31
|
expect(_.get(r, 'error.additionalInfo')).toEqual(_.get(test, 'additionalInfo'))
|