ac-sanitizer 5.0.0 → 5.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 CHANGED
@@ -1,4 +1,32 @@
1
1
 
2
+ # [5.1.0](https://github.com/mmpro/ac-sanitizer/compare/v5.0.1..v5.1.0) (2025-09-10 10:32:21)
3
+
4
+
5
+ ### Feature
6
+
7
+ * **App:** Add option to convert a string with splitSpaceSeparated | MP | [d5974ea9286ceaa9cd6a3273e713ccf002cc7e7c](https://github.com/mmpro/ac-sanitizer/commit/d5974ea9286ceaa9cd6a3273e713ccf002cc7e7c)
8
+ Converts an URL encoded, space separated string into an array (e.g. for OAuth scopes)
9
+ Related issues:
10
+ ### Chores
11
+
12
+ * **App:** Updated packages | MP | [3f832431642e3ae5705eb45f1c823ba5f29d9d50](https://github.com/mmpro/ac-sanitizer/commit/3f832431642e3ae5705eb45f1c823ba5f29d9d50)
13
+ Updated packages
14
+ Related issues:
15
+
16
+ ## [5.0.1](https://github.com/mmpro/ac-sanitizer/compare/v5.0.0..v5.0.1) (2025-08-31 12:35:43)
17
+
18
+
19
+ ### Bug Fix
20
+
21
+ * **App:** Add option unique for arrays | MP | [2484bd72c6ca31610361056eb05dd6b0b05bf3c3](https://github.com/mmpro/ac-sanitizer/commit/2484bd72c6ca31610361056eb05dd6b0b05bf3c3)
22
+ If unique is true, duplicates will be removed from array
23
+ Related issues:
24
+ ### Chores
25
+
26
+ * **App:** Updated packages | MP | [f4689d9b3bdbde42098fef0827cad691dd5d651f](https://github.com/mmpro/ac-sanitizer/commit/f4689d9b3bdbde42098fef0827cad691dd5d651f)
27
+ Updated packages
28
+ Related issues:
29
+
2
30
  # [5.0.0](https://github.com/mmpro/ac-sanitizer/compare/v4.2.1..v5.0.0) (2025-05-21 15:57:54)
3
31
 
4
32
 
package/README.md CHANGED
@@ -80,6 +80,7 @@ integer | 60.1 -> 60 | Convert incoming number to integer - this way you can mak
80
80
  string | Hello Developer -> Hello (with maxLength = 5) | Reduce string to max length
81
81
  base64 | SGVsbG8= -> Hello | Convert base64 encoded string to UTF-8 string
82
82
  iso-639 | { iso-639-2: 'tlh', translations: [] } -> tlh (with convert=iso-639-2) | Returns only the select property for the ISO-639 object
83
+ splitSpaceSeparated | user_read%20user_write -> ['user_read', 'user_write'] | Converts an URL encoded, space separated string into an array (e.g. for OAuth scopes)
83
84
 
84
85
 
85
86
  ## Available types
@@ -87,6 +88,7 @@ iso-639 | { iso-639-2: 'tlh', translations: [] } -> tlh (with convert=iso-639-2)
87
88
  Type | Options | Remarks
88
89
  --- | --- | --- |
89
90
  any | | Any can be string, integer, boolean, object or array - it will be automatically detected.
91
+ array | unique | If unique=true, duplicate entries will be removed from array
90
92
  base64 | | Checks if a string is base64 encoded, optional with field option "convert" (to string)
91
93
  boolean | |
92
94
  cidr | | Check CIDR, see example
@@ -110,7 +112,7 @@ number | | Should no be used - use integer, long, short, floag
110
112
  ratio | | x:y
111
113
  rgb | | Check for valid RGB value (r,g,b) or (r%,g%, b%)
112
114
  short | | 0 - 2^15
113
- string | minLength (int), maxLength (int), ignoreCase | With ignoreCase=true enum checks are case insensitive (e.g. abc in ['ABC'] is valid)
115
+ string | minLength (int), maxLength (int), ignoreCase, splitSpaceSeparated | With ignoreCase=true enum checks are case insensitive (e.g. abc in ['ABC'] is valid)
114
116
  url| protocols, require_tld, require_protocol | Default values: protocols ['http', 'https'], required_tld true, require_protocol true
115
117
 
116
118
  # Examples
package/index.js CHANGED
@@ -254,6 +254,15 @@ const sanitizer = function() {
254
254
  }
255
255
  else error = { message: fieldName + '_stringTooLong_maxLength' + field.maxLength }
256
256
  }
257
+ if (_.get(field, 'convert') === 'splitSpaceSeparated') {
258
+ try {
259
+ const decoded = decodeURIComponent(value)
260
+ _.set(paramsToCheck, fieldName, decoded.split(' ').filter(Boolean))
261
+ }
262
+ catch(e) {
263
+ error = { message: fieldName + '_couldNotDecodeURI' }
264
+ }
265
+ }
257
266
  }
258
267
  else if (field.type === 'boolean') {
259
268
  // GET params are strings -> try to make the boolean
@@ -300,6 +309,8 @@ const sanitizer = function() {
300
309
  if (!error && _.isFunction(_.get(schema, 'verify'))) {
301
310
  error = schema.verify(value)
302
311
  }
312
+
313
+ if (field.unique) _.set(paramsToCheck, fieldName, _.uniqWith(value, _.isEqual))
303
314
  }
304
315
  else if (field.type === 'object') {
305
316
  if (!_.isPlainObject(value)) error = { message: fieldName + '_' + getTypeMapping(field.type, 'errorMessage') }
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": "5.0.0",
7
+ "version": "5.1.0",
8
8
  "homepage": "https://www.admiralcloud.com",
9
9
  "dependencies": {
10
- "ac-countrylist": "^1.0.13",
11
- "ac-file-extensions": "^2.0.10",
12
- "ac-ip": "^4.1.3",
10
+ "ac-countrylist": "^1.0.14",
11
+ "ac-file-extensions": "^2.0.11",
12
+ "ac-ip": "^4.1.4",
13
13
  "chai": "^4.5.0",
14
14
  "date-and-time": "^3.6.0",
15
15
  "hashids": "^2.3.0",
16
16
  "lodash": "^4.17.21",
17
- "validator": "^13.15.0"
17
+ "validator": "^13.15.15"
18
18
  },
19
19
  "devDependencies": {
20
- "ac-semantic-release": "^0.4.6",
20
+ "ac-semantic-release": "^0.4.7",
21
21
  "c8": "^10.1.3",
22
- "eslint": "^9.27.0",
23
- "mocha": "^11.3.0"
22
+ "eslint": "^9.35.0",
23
+ "mocha": "^11.7.2"
24
24
  },
25
25
  "scripts": {
26
26
  "test": "mocha --reporter spec --bail",
@@ -41,6 +41,8 @@ module.exports = {
41
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
42
  { name: 'Array of urls with https', type: 'array', valueType: 'url', value: ['https://www.admiralcloud.com'], expected: ['https://www.admiralcloud.com'] },
43
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
+ { name: 'Array with unique values', type: 'array', value: ['a', 'b', 'a'], unique: true, expected: ['a', 'b'] },
45
+ { name: 'Array with unique objects', type: 'array', value: [{ a: 1, x: true }, { a: 2, x: true }, { a: 2, x: false }, { a: 1, x: true }], unique: true, expected: [{ a: 1, x: true }, { a: 2, x: true }, { a: 2, x: false }] },
44
46
  ]
45
47
 
46
48
  runValidationTests(baseTests, 'array', { equalityCheck: 'eql' })
@@ -20,6 +20,7 @@ module.exports = {
20
20
  { name: 'Valid - uppercase vs lowercase', type: 'string', ignoreCase: true, value: 'ABC', enum: ['abc'], expected: 'ABC' },
21
21
  { name: 'Invalid - value too short', type: 'string', minLength: 5, value: 'ABC', error: 'string_stringTooShort_minLength5' },
22
22
  { name: 'Valid - value is longer than 5 chars', type: 'string', minLength: 5, value: 'ABCDEF', expected: 'ABCDEF' },
23
+ { name: 'Valid - value is a URL encoded, space separated string', type: 'string', convert: 'splitSpaceSeparated', value: 'one%20two%20three', expected: ['one', 'two', 'three'] }
23
24
  ]
24
25
 
25
26
  runValidationTests(baseTests, 'string', { equalityCheck: 'eql' })