ac-sanitizer 3.10.5 → 3.10.7
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 +25 -0
- package/README.md +12 -2
- package/index.js +7 -0
- package/package.json +6 -6
- package/test/tests/number.js +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
<a name="3.10.7"></a>
|
|
2
|
+
|
|
3
|
+
## [3.10.7](https://github.com/mmpro/ac-sanitizer/compare/v3.10.6..v3.10.7) (2023-01-28 19:37:40)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fix
|
|
7
|
+
|
|
8
|
+
* **App:** Package updates | MP | [ea995e12e8fb33f161346643e842415265d8701c](https://github.com/mmpro/ac-sanitizer/commit/ea995e12e8fb33f161346643e842415265d8701c)
|
|
9
|
+
Package updates
|
|
10
|
+
Related issues: [undefined/undefined#master](undefined/browse/master)
|
|
11
|
+
### Documentation
|
|
12
|
+
|
|
13
|
+
* **App:** Updated README | MP | [38ed9526f3c60b79802e573ff6ac3c7dec41c95f](https://github.com/mmpro/ac-sanitizer/commit/38ed9526f3c60b79802e573ff6ac3c7dec41c95f)
|
|
14
|
+
Minor update
|
|
15
|
+
Related issues: [undefined/undefined#master](undefined/browse/master)
|
|
16
|
+
<a name="3.10.6"></a>
|
|
17
|
+
|
|
18
|
+
## [3.10.6](https://github.com/mmpro/ac-sanitizer/compare/v3.10.5..v3.10.6) (2022-07-23 06:54:26)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fix
|
|
22
|
+
|
|
23
|
+
* **App:** Allow convert with number | MP | [3e3d951a275b4c3e90654071cc2dcafb303742f2](https://github.com/mmpro/ac-sanitizer/commit/3e3d951a275b4c3e90654071cc2dcafb303742f2)
|
|
24
|
+
In order to be more lenient you can add property convert to numbers (e.g. integer). This way incoming float value will be converted to integer instead of returning an error.
|
|
25
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
1
26
|
<a name="3.10.5"></a>
|
|
2
27
|
|
|
3
28
|
## [3.10.5](https://github.com/mmpro/ac-sanitizer/compare/v3.10.4..v3.10.5) (2022-06-25 09:02:28)
|
package/README.md
CHANGED
|
@@ -47,12 +47,13 @@ Parameter | Type | Remarks
|
|
|
47
47
|
field | string | Name of the field
|
|
48
48
|
type | string | Type of the field to sanitize, see below for available values
|
|
49
49
|
required | [boolean OR string] | Set to true if required or set a path[^1] to a param (if that param is set, this value is required)
|
|
50
|
-
enum | [array
|
|
50
|
+
enum | [array OR string] | Optional list of allowed values. You can a string placeholder for certain standard lists (see below)
|
|
51
51
|
adminLevel | [integer] | Optional adminLevel required for this field
|
|
52
52
|
omitFields | [boolean] | If adminLevel is set and you do not have the proper adminLevel the sanitizer will just omit the field (and not return an error) if omitFields is true
|
|
53
|
-
convert | [boolean
|
|
53
|
+
convert | [boolean OR string] | Some types can be automatically converted (e.g. base64 to string)
|
|
54
54
|
valueType | [string] | Use it to sanitize values of an array by defining the allowed type here
|
|
55
55
|
strict | [boolean] | For objects only - if true and payload contains a property not defined, an error will be returned.
|
|
56
|
+
nullAllowed | [boolean] | If true, sending NULL is allowed.
|
|
56
57
|
|
|
57
58
|
[^1]: The path must be set with the parent propery as root, e.g. the actual field is settings.video.width, in property video the condition is then just "width" not the full path.
|
|
58
59
|
|
|
@@ -65,6 +66,15 @@ iso-639-1 | ISO 639-1 entries | e.g. de, en, fr, es...
|
|
|
65
66
|
iso-639-2 | ISO 639-2 entries | e.g. deu, eng, fra ...
|
|
66
67
|
countrylist | list of country names | e.g. Laos, Brazil, Norway...
|
|
67
68
|
|
|
69
|
+
### Convert
|
|
70
|
+
Some types allow automatic conversion:
|
|
71
|
+
Type | Example | Remarks
|
|
72
|
+
--- | --- | --- |
|
|
73
|
+
integer | 60.1 -> 60 | Convert incoming number to integer - this way you can make your check more lenient
|
|
74
|
+
string | Hello Developer -> Hello (with maxLength = 5) | Reduce string to max length
|
|
75
|
+
base64 | SGVsbG8= -> Hello | Convert base64 encoded string to UTF-8 string
|
|
76
|
+
iso-639 | { iso-639-2: 'tlh', translations: [] } -> tlh (with convert=iso-639-2) | Returns only the select property for the ISO-639 object
|
|
77
|
+
|
|
68
78
|
|
|
69
79
|
## Available types
|
|
70
80
|
|
package/index.js
CHANGED
|
@@ -200,6 +200,13 @@ const sanitizer = function() {
|
|
|
200
200
|
if (field.type === 'number') console.error('SANITIZER - number should not be used, be more precise')
|
|
201
201
|
if (field.type === 'number') field.type = 'integer'
|
|
202
202
|
|
|
203
|
+
|
|
204
|
+
if (field.type !== 'float' && _.get(field, 'convert')) {
|
|
205
|
+
// make sure the value is integer
|
|
206
|
+
value = parseInt(value)
|
|
207
|
+
_.set(paramsToCheck, fieldName, value)
|
|
208
|
+
}
|
|
209
|
+
|
|
203
210
|
if (field.type === 'float' && value !== parseFloat(value)) {
|
|
204
211
|
error = { message: fieldName + '_not_' + field.type, additionalInfo: { value } }
|
|
205
212
|
}
|
package/package.json
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "admiralcloud/ac-sanitizer",
|
|
7
|
-
"version": "3.10.
|
|
7
|
+
"version": "3.10.7",
|
|
8
8
|
"homepage": "https://www.admiralcloud.com",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"ac-countrylist": "^1.0.7",
|
|
11
11
|
"ac-file-extensions": "^2.0.5",
|
|
12
12
|
"ac-ip": "^2.0.0",
|
|
13
|
-
"chai": "^4.3.
|
|
14
|
-
"date-and-time": "^2.4.
|
|
13
|
+
"chai": "^4.3.7",
|
|
14
|
+
"date-and-time": "^2.4.2",
|
|
15
15
|
"hashids": "^2.2.10",
|
|
16
16
|
"lodash": "^4.17.21",
|
|
17
17
|
"validator": "^13.7.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"ac-semantic-release": "^0.3.
|
|
21
|
-
"eslint": "^8.
|
|
22
|
-
"mocha": "^10.
|
|
20
|
+
"ac-semantic-release": "^0.3.4",
|
|
21
|
+
"eslint": "^8.32.0",
|
|
22
|
+
"mocha": "^10.2.0",
|
|
23
23
|
"nyc": "^15.1.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
package/test/tests/number.js
CHANGED
|
@@ -74,7 +74,7 @@ module.exports = {
|
|
|
74
74
|
integer: _.get(test, 'value')
|
|
75
75
|
},
|
|
76
76
|
fields: [
|
|
77
|
-
{ field: 'integer', type: _.get(test, 'type'), subtype: _.get(test, 'subtype'), required: _.get(test, 'required'), range: _.get(test, 'range') }
|
|
77
|
+
{ field: 'integer', type: _.get(test, 'type'), subtype: _.get(test, 'subtype'), required: _.get(test, 'required'), convert: _.get(test, 'convert'), range: _.get(test, 'range') }
|
|
78
78
|
]
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -100,7 +100,9 @@ module.exports = {
|
|
|
100
100
|
{ name: 'Unsigned float -1 - should fail and display additionalInfo', type: 'float', value: -1, error: 'number_outOfRange', additionalInfo: { range: [0,2147483648], value: -1 } },
|
|
101
101
|
{ name: 'Array of numbers with one entry', type: 'integer', value: [123], error: 'number_notAFiniteNumber' },
|
|
102
102
|
{ name: 'Array of numbers with multiple entries', type: 'integer', value: [123, 456], error: 'number_notAFiniteNumber' },
|
|
103
|
-
{ name: 'Check float', type: 'float', range: [-90, 90], value: 53.15, expected: 53.15 }
|
|
103
|
+
{ name: 'Check float', type: 'float', range: [-90, 90], value: 53.15, expected: 53.15 },
|
|
104
|
+
{ name: 'Integer as float - 60.1 - should fail', type: 'integer', value: 60.1, error: 'number_typeIncorrect' },
|
|
105
|
+
{ name: 'Integer as float with convert - 60.1 - should work', type: 'integer', convert: true, value: 60.1, expected: 60 },
|
|
104
106
|
]
|
|
105
107
|
|
|
106
108
|
_.forEach(tests, (test) => {
|
|
@@ -110,7 +112,7 @@ module.exports = {
|
|
|
110
112
|
number: _.get(test, 'value')
|
|
111
113
|
},
|
|
112
114
|
fields: [
|
|
113
|
-
{ field: 'number', type: _.get(test, 'type'), subtype: _.get(test, 'subtype'), required: _.get(test, 'required'), range: _.get(test, 'range') }
|
|
115
|
+
{ field: 'number', type: _.get(test, 'type'), subtype: _.get(test, 'subtype'), required: _.get(test, 'required'), convert: _.get(test, 'convert'), range: _.get(test, 'range') }
|
|
114
116
|
]
|
|
115
117
|
}
|
|
116
118
|
|