ac-sanitizer 4.0.16 → 4.1.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.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/index.js +10 -0
- package/package.json +6 -6
- package/test/tests/string.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
# [4.1.0](https://github.com/mmpro/ac-sanitizer/compare/v4.0.16..v4.1.0) (2025-01-25 10:01:18)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Feature
|
|
6
|
+
|
|
7
|
+
* **App:** Add option to ingoreCase for string/enum | MP | [92c41c2a5b3e6634e8458acadee47fad1d5e5dc3](https://github.com/mmpro/ac-sanitizer/commit/92c41c2a5b3e6634e8458acadee47fad1d5e5dc3)
|
|
8
|
+
With ignoreCase=true enum checks are case insensitive (e.g. abc in [ABC] is valid)
|
|
9
|
+
Related issues:
|
|
10
|
+
### Chores
|
|
11
|
+
|
|
12
|
+
* **App:** Updated packages | MP | [763b5fce7a31e867424ffb9bddb4a1b721ac0d9b](https://github.com/mmpro/ac-sanitizer/commit/763b5fce7a31e867424ffb9bddb4a1b721ac0d9b)
|
|
13
|
+
Updated packages
|
|
14
|
+
Related issues:
|
|
1
15
|
<a name="4.0.16"></a>
|
|
2
16
|
|
|
3
17
|
## [4.0.16](https://github.com/mmpro/ac-sanitizer/compare/v4.0.15..v4.0.16) (2024-09-20 12:35:35)
|
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ number | | Should no be used - use integer, long, short, floag
|
|
|
110
110
|
ratio | | x:y
|
|
111
111
|
rgb | | Check for valid RGB value (r,g,b) or (r%,g%, b%)
|
|
112
112
|
short | | 0 - 2^15
|
|
113
|
-
string | minLength (int), maxLength (int)|
|
|
113
|
+
string | minLength (int), maxLength (int), ignoreCase | With ignoreCase=true enum checks are case insensitive (e.g. abc in ['ABC'] is valid)
|
|
114
114
|
url| protocols, require_tld, require_protocol | Default values: protocols ['http', 'https'], required_tld true, require_protocol true
|
|
115
115
|
|
|
116
116
|
# Examples
|
package/index.js
CHANGED
|
@@ -497,6 +497,14 @@ const sanitizer = function() {
|
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
if (!error && allowedValues && value) {
|
|
500
|
+
let orgValue
|
|
501
|
+
if (field.ignoreCase && _.isString(value)) {
|
|
502
|
+
// convert value and allowesValues to lowercase
|
|
503
|
+
orgValue = _.clone(orgValue)
|
|
504
|
+
value = _.toLower(value)
|
|
505
|
+
allowedValues = _.map(allowedValues, _.toLower)
|
|
506
|
+
}
|
|
507
|
+
|
|
500
508
|
if (_.isArray(value)) {
|
|
501
509
|
if (_.size(value) && !_.size(_.intersectionWith(value, allowedValues, _.isEqual))) {
|
|
502
510
|
error = { message: fieldName + '_notAnAllowedValue', additionalInfo: { value } }
|
|
@@ -508,6 +516,8 @@ const sanitizer = function() {
|
|
|
508
516
|
else if (_.indexOf(allowedValues, value) < 0) {
|
|
509
517
|
error = { message: fieldName + '_notAnAllowedValue', additionalInfo: { value } }
|
|
510
518
|
}
|
|
519
|
+
|
|
520
|
+
if (orgValue) value = orgValue
|
|
511
521
|
}
|
|
512
522
|
|
|
513
523
|
if (error && field.customErrorMessage) _.set(error, 'message', field.customErrorMessage)
|
package/package.json
CHANGED
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "admiralcloud/ac-sanitizer",
|
|
7
|
-
"version": "4.0
|
|
7
|
+
"version": "4.1.0",
|
|
8
8
|
"homepage": "https://www.admiralcloud.com",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"ac-countrylist": "^1.0.12",
|
|
11
11
|
"ac-file-extensions": "^2.0.10",
|
|
12
12
|
"ac-ip": "^4.1.2",
|
|
13
13
|
"chai": "^4.5.0",
|
|
14
|
-
"date-and-time": "^3.
|
|
14
|
+
"date-and-time": "^3.6.0",
|
|
15
15
|
"hashids": "^2.3.0",
|
|
16
16
|
"lodash": "^4.17.21",
|
|
17
17
|
"validator": "^13.12.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"ac-semantic-release": "^0.4.
|
|
21
|
-
"c8": "^10.1.
|
|
22
|
-
"eslint": "^9.
|
|
23
|
-
"mocha": "^
|
|
20
|
+
"ac-semantic-release": "^0.4.5",
|
|
21
|
+
"c8": "^10.1.3",
|
|
22
|
+
"eslint": "^9.19.0",
|
|
23
|
+
"mocha": "^11.1.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "mocha --reporter spec --bail",
|
package/test/tests/string.js
CHANGED
|
@@ -16,6 +16,8 @@ module.exports = {
|
|
|
16
16
|
{ name: 'Valid from enum', type: 'string', value: 'play', enum: ['play', 'pause'], expected: 'play' },
|
|
17
17
|
{ name: 'Invalid from enum', type: 'string', value: 'stop', enum: ['play', 'pause'], error: 'string_notAnAllowedValue', additionalInfo: { value: 'stop' } },
|
|
18
18
|
{ name: 'Valid string from randomValue function', type: 'string', value: randomValue, expected: randomValue },
|
|
19
|
+
{ name: 'Invalid - uppercase vs lowercase', type: 'string', value: 'ABC', enum: ['abc'], error: 'string_notAnAllowedValue' },
|
|
20
|
+
{ name: 'Valid - uppercase vs lowercase', type: 'string', ignoreCase: true, value: 'ABC', enum: ['abc'], expected: 'ABC' },
|
|
19
21
|
]
|
|
20
22
|
|
|
21
23
|
|
|
@@ -26,7 +28,7 @@ module.exports = {
|
|
|
26
28
|
string: _.get(test, 'value')
|
|
27
29
|
},
|
|
28
30
|
fields: [
|
|
29
|
-
{ field: 'string', type: _.get(test, 'type'), required: _.get(test, 'required'), enum: _.get(test, 'enum'), minLength: _.get(test, 'minLength'), maxLength: _.get(test, 'maxLength'), convert: _.get(test, 'convert') }
|
|
31
|
+
{ field: 'string', type: _.get(test, 'type'), ignoreCase: _.get(test, 'ignoreCase'), required: _.get(test, 'required'), enum: _.get(test, 'enum'), minLength: _.get(test, 'minLength'), maxLength: _.get(test, 'maxLength'), convert: _.get(test, 'convert') }
|
|
30
32
|
]
|
|
31
33
|
}
|
|
32
34
|
|