ac-sanitizer 4.2.0 → 5.0.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 CHANGED
@@ -1,4 +1,34 @@
1
1
 
2
+ # [5.0.0](https://github.com/mmpro/ac-sanitizer/compare/v4.2.1..v5.0.0) (2025-05-21 15:57:54)
3
+
4
+
5
+ ### Bug Fix
6
+
7
+ * **App:** Do not require minLength of 2 chars for strings | MP | [ff2c0d4c453725cfe3f6ecd84ca5160bd907b9b1](https://github.com/mmpro/ac-sanitizer/commit/ff2c0d4c453725cfe3f6ecd84ca5160bd907b9b1)
8
+ If you want to set minLength, you can still do so, but default for string is 0 = no minLength
9
+ Related issues:
10
+ ### Tests
11
+
12
+ * **App:** Fixed test | MP | [0d335b956b012023bbe6f3214d2d961ff8baa04a](https://github.com/mmpro/ac-sanitizer/commit/0d335b956b012023bbe6f3214d2d961ff8baa04a)
13
+ Fixed test
14
+ Related issues:
15
+ ## BREAKING CHANGES
16
+ * **App:** MinLength of 2 chars for strings is no longer hardcoded/required
17
+
18
+ ## [4.2.1](https://github.com/mmpro/ac-sanitizer/compare/v4.2.0..v4.2.1) (2025-05-19 06:12:14)
19
+
20
+
21
+ ### Bug Fix
22
+
23
+ * **App:** Fixed and improved valueType with array | MP | [0bfa6135e4588a5f24a11ab2a3024d608fe8aa21](https://github.com/mmpro/ac-sanitizer/commit/0bfa6135e4588a5f24a11ab2a3024d608fe8aa21)
24
+ If you set valueType for an array, we will now check all properties and return an error is there is any issue.
25
+ Related issues:
26
+ ### Chores
27
+
28
+ * **App:** Updated packages | MP | [699b8a2a7a4d41cc7f58318e400937dfba21cf30](https://github.com/mmpro/ac-sanitizer/commit/699b8a2a7a4d41cc7f58318e400937dfba21cf30)
29
+ Updated packages
30
+ Related issues:
31
+
2
32
  # [4.2.0](https://github.com/mmpro/ac-sanitizer/compare/v4.1.4..v4.2.0) (2025-05-09 07:40:18)
3
33
 
4
34
 
package/index.js CHANGED
@@ -69,7 +69,7 @@ const sanitizer = function() {
69
69
  _.some(fields, (field) => {
70
70
  // FIELD definitions
71
71
  let fieldName = field.field
72
- let minLength = _.isNumber(field.minLength) ? field.minLength : 2
72
+ let minLength = _.isNumber(field.minLength) ? field.minLength : 0
73
73
  let allowedValues = _.get(field, 'enum', _.get(field, 'isMemberOf.group'))
74
74
  if (_.isString(allowedValues)) {
75
75
  // placeholder for enum:
@@ -274,9 +274,15 @@ const sanitizer = function() {
274
274
  else if (field.valueType) {
275
275
  // very value of the array must be of this type
276
276
  _.every(value, (v, index, value) => {
277
+ const { valueType, type, ...fieldProps } = field
278
+
277
279
  const fieldsToCheck = {
278
280
  params: {},
279
- fields: [{ field: fieldName, type: _.get(field, 'valueType'), minLength: _.get(field, 'minLength'), properties: _.get(field, 'properties'), wildcardAllowed: _.get(field, 'wildcardAllowed') }]
281
+ fields: [{
282
+ field: fieldName,
283
+ type: valueType,
284
+ ...fieldProps
285
+ }]
280
286
  }
281
287
  _.set(fieldsToCheck, `params.${fieldName}`, v)
282
288
  const check = checkAndSanitizeValues(fieldsToCheck)
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": "4.2.0",
7
+ "version": "5.0.0",
8
8
  "homepage": "https://www.admiralcloud.com",
9
9
  "dependencies": {
10
10
  "ac-countrylist": "^1.0.13",
@@ -19,8 +19,8 @@
19
19
  "devDependencies": {
20
20
  "ac-semantic-release": "^0.4.6",
21
21
  "c8": "^10.1.3",
22
- "eslint": "^9.26.0",
23
- "mocha": "^11.2.2"
22
+ "eslint": "^9.27.0",
23
+ "mocha": "^11.3.0"
24
24
  },
25
25
  "scripts": {
26
26
  "test": "mocha --reporter spec --bail",
@@ -37,9 +37,11 @@ module.exports = {
37
37
  value: [{ p1: 'isAString', p2: 'shouldBeRemoved' }, { p1: 'isAString2', p2: 'shouldBeRemoved2' }],
38
38
  expected: [{ p1: 'isAString' }, { p1: 'isAString2' }]
39
39
  },
40
- { name: 'Array of strings with enum - uppercase vs lowercase', type: 'array', valueType: 'string', value: ['ABC'], enum: ['abc'], error: 'array_notAnAllowedValue' },
41
- { name: 'Array of strings with enum - uppercase vs lowercase - with ignoreCase', type: 'array', valueType: 'string', ignoreCase: true, value: ['ABC', 'DEF'], enum: ['abc'], expected: ['ABC'] },
42
- ]
40
+ { name: 'Array of strings with enum - uppercase vs lowercase', type: 'array', valueType: 'string', value: ['ABC'], enum: ['abc'], error: 'array_atLeastOneValueFailed' },
41
+ { name: 'Array of strings with enum - uppercase vs lowercase - with ignoreCase', type: 'array', valueType: 'string', ignoreCase: true, value: ['ABC', 'DEF'], enum: ['abc'], error: 'array_atLeastOneValueFailed' },
42
+ { name: 'Array of urls with https', type: 'array', valueType: 'url', value: ['https://www.admiralcloud.com'], expected: ['https://www.admiralcloud.com'] },
43
+ { name: 'Array of urls with http and https - only https is allowed', type: 'array', valueType: 'url', protocols: ['https'], value: ['http://www.admiralcloud.com'], error: 'array_atLeastOneValueFailed' },
44
+ ]
43
45
 
44
46
  runValidationTests(baseTests, 'array', { equalityCheck: 'eql' })
45
47
  }
@@ -18,6 +18,8 @@ module.exports = {
18
18
  { name: 'Valid string from randomValue function', type: 'string', value: randomValue, expected: randomValue },
19
19
  { name: 'Invalid - uppercase vs lowercase', type: 'string', value: 'ABC', enum: ['abc'], error: 'string_notAnAllowedValue' },
20
20
  { name: 'Valid - uppercase vs lowercase', type: 'string', ignoreCase: true, value: 'ABC', enum: ['abc'], expected: 'ABC' },
21
+ { name: 'Invalid - value too short', type: 'string', minLength: 5, value: 'ABC', error: 'string_stringTooShort_minLength5' },
22
+ { name: 'Valid - value is longer than 5 chars', type: 'string', minLength: 5, value: 'ABCDEF', expected: 'ABCDEF' },
21
23
  ]
22
24
 
23
25
  runValidationTests(baseTests, 'string', { equalityCheck: 'eql' })
package/test/tests/url.js CHANGED
@@ -7,7 +7,7 @@ module.exports = {
7
7
  const baseTests = [
8
8
  { name: 'Valid url', type: 'url', value: 'https://www.admiralcloud.com', expected: 'https://www.admiralcloud.com' },
9
9
  { name: 'Invalid url', type: 'url', value: 'www.admiralcloud.com', error: 'url_notAValidURL' },
10
- { name: 'Invalid url - wrong protocol', type: 'url', value: 'ftp://www.admiralcloud.com', error: 'url_notAValidURL' },
10
+ { name: 'Invalid url - wrong protocol', type: 'url', value: 'ftp://www.admiralcloud.com', error: 'url_notAValidURL' }
11
11
  ]
12
12
 
13
13
  runValidationTests(baseTests, 'url')