xzwebx-httpfilter 1.2.3 → 1.3.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/HttpFilter.js +133 -37
- package/package.json +1 -1
package/HttpFilter.js
CHANGED
|
@@ -125,44 +125,54 @@ function CheckReq(req, res, next) {
|
|
|
125
125
|
}
|
|
126
126
|
function cycleCheckParams(msgFieldMap, data) {
|
|
127
127
|
let retMsgData = null
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
!msgFieldMap['__FieldCfg'].ifMust) {
|
|
128
|
+
|
|
129
|
+
if (!msgFieldMap) {
|
|
131
130
|
return null
|
|
132
131
|
}
|
|
133
132
|
|
|
133
|
+
let fCfgItem = null
|
|
134
|
+
let isRoot = true
|
|
135
|
+
if (msgFieldMap['__FieldCfg']) {
|
|
136
|
+
isRoot = false
|
|
137
|
+
fCfgItem = msgFieldMap['__FieldCfg']
|
|
138
|
+
}
|
|
139
|
+
|
|
134
140
|
for (let fieldName in msgFieldMap) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
141
|
+
if (isRoot) {
|
|
142
|
+
fCfgItem = msgFieldMap[fieldName]['__FieldCfg']
|
|
143
|
+
}
|
|
140
144
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
if (fCfgItem.fieldType == 'STR') {
|
|
146
|
+
retMsgData = IsStringOk(fCfgItem, data)
|
|
147
|
+
} else if (fCfgItem.fieldType == 'INT') {
|
|
148
|
+
retMsgData = IsIntOk(fCfgItem, data)
|
|
149
|
+
} else if (fCfgItem.fieldType == 'OBJ') {
|
|
150
|
+
retMsgData = IsObjOk(fCfgItem, data)
|
|
151
|
+
} else if (fCfgItem.fieldType == 'LIST') {
|
|
152
|
+
retMsgData = IsListOk(fCfgItem, data)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (retMsgData) {
|
|
156
|
+
return retMsgData
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (fieldName == '__FieldCfg') {
|
|
154
160
|
continue
|
|
155
161
|
}
|
|
156
|
-
let fatherFieldType =
|
|
157
|
-
if (fatherFieldType == 'LIST' || (fatherFieldType == 'OBJ' &&
|
|
162
|
+
let fatherFieldType = fCfgItem.fieldType
|
|
163
|
+
if (fatherFieldType == 'LIST' || (fatherFieldType == 'OBJ' && fCfgItem.keyType == 'VOBJ')) {
|
|
158
164
|
for (let idx in data) {
|
|
159
|
-
retMsgData = cycleCheckParams(
|
|
165
|
+
retMsgData = cycleCheckParams(msgFieldMap[fieldName], data[idx])
|
|
160
166
|
if (retMsgData) {
|
|
161
167
|
return retMsgData
|
|
162
168
|
}
|
|
163
169
|
}
|
|
164
170
|
} else {
|
|
165
|
-
|
|
171
|
+
if (isRoot) {
|
|
172
|
+
retMsgData = cycleCheckParams(msgFieldMap[fieldName], data)
|
|
173
|
+
} else {
|
|
174
|
+
retMsgData = cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
|
|
175
|
+
}
|
|
166
176
|
}
|
|
167
177
|
|
|
168
178
|
if (retMsgData) {
|
|
@@ -172,6 +182,19 @@ function cycleCheckParams(msgFieldMap, data) {
|
|
|
172
182
|
return null
|
|
173
183
|
}
|
|
174
184
|
function IsStringOk(fCfgItem, paramValue) {
|
|
185
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
186
|
+
return null
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
190
|
+
data == undefined ||
|
|
191
|
+
data == null ||
|
|
192
|
+
data == '' ||
|
|
193
|
+
(typeof data === 'object' && !data.length && !Object.keys(data).length))
|
|
194
|
+
) {
|
|
195
|
+
return null
|
|
196
|
+
}
|
|
197
|
+
|
|
175
198
|
if (!paramValue) {
|
|
176
199
|
return ['NULL_STR_FIELD', fCfgItem.fieldUrl]
|
|
177
200
|
}
|
|
@@ -192,7 +215,7 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
192
215
|
}
|
|
193
216
|
}
|
|
194
217
|
} else {
|
|
195
|
-
if (parseInt(rule.exprVal[0])
|
|
218
|
+
if (paramValue.length >= parseInt(rule.exprVal[0]) && paramValue.length <= parseInt(rule.exprVal[1])) {
|
|
196
219
|
isPass = true
|
|
197
220
|
}
|
|
198
221
|
}
|
|
@@ -205,25 +228,48 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
205
228
|
}
|
|
206
229
|
} else if (rule.checkType == 'ENU') {
|
|
207
230
|
if (rule.isCaseSensitive == 1) {
|
|
208
|
-
if (rule.exprVal && rule.exprVal.length
|
|
209
|
-
if (rule.
|
|
210
|
-
|
|
231
|
+
if (rule.exprVal && rule.exprVal.length) {
|
|
232
|
+
if (rule.isMatched === 1) {
|
|
233
|
+
if (!rule.exprVal.includes(paramValue)) {
|
|
234
|
+
if (rule.ruleDesc) {
|
|
235
|
+
return rule.ruleDesc
|
|
236
|
+
}
|
|
237
|
+
return ['WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
if (rule.exprVal.includes(paramValue)) {
|
|
241
|
+
if (rule.ruleDesc) {
|
|
242
|
+
return rule.ruleDesc
|
|
243
|
+
}
|
|
244
|
+
return ['EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
245
|
+
}
|
|
211
246
|
}
|
|
212
|
-
return ['WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
213
247
|
}
|
|
214
248
|
} else {
|
|
215
249
|
let isPass = false
|
|
216
250
|
for (let k in rule.exprVal) {
|
|
217
|
-
if (rule.
|
|
251
|
+
if (rule.isMatched === 1) {
|
|
252
|
+
if (rule.exprVal[k].toUpperCase() === paramValue.toUpperCase()) {
|
|
253
|
+
isPass = true
|
|
254
|
+
break
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
218
257
|
isPass = true
|
|
219
|
-
|
|
258
|
+
if (rule.exprVal[k].toUpperCase() == paramValue.toUpperCase()) {
|
|
259
|
+
isPass = false
|
|
260
|
+
break
|
|
261
|
+
}
|
|
220
262
|
}
|
|
221
263
|
}
|
|
222
264
|
if (!isPass) {
|
|
223
265
|
if (rule.ruleDesc) {
|
|
224
266
|
return rule.ruleDesc
|
|
225
267
|
}
|
|
226
|
-
|
|
268
|
+
if (rule.isMatched === 1) {
|
|
269
|
+
return ['WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
270
|
+
} else {
|
|
271
|
+
return ['EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
272
|
+
}
|
|
227
273
|
}
|
|
228
274
|
}
|
|
229
275
|
} else if (rule.checkType == 'REGEX') {
|
|
@@ -256,6 +302,19 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
256
302
|
return null
|
|
257
303
|
}
|
|
258
304
|
function IsIntOk(fCfgItem, paramValue) {
|
|
305
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
306
|
+
return null
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
310
|
+
data == undefined ||
|
|
311
|
+
data == null ||
|
|
312
|
+
data == '' ||
|
|
313
|
+
(typeof data === 'object' && !data.length && !Object.keys(data).length))
|
|
314
|
+
) {
|
|
315
|
+
return null
|
|
316
|
+
}
|
|
317
|
+
|
|
259
318
|
if (paramValue == undefined) {
|
|
260
319
|
return ['NULL_INT_FIELD', fCfgItem.fieldUrl]
|
|
261
320
|
}
|
|
@@ -288,11 +347,22 @@ function IsIntOk(fCfgItem, paramValue) {
|
|
|
288
347
|
return ['WRONG_INT_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
289
348
|
}
|
|
290
349
|
} else if (rule.checkType == 'ENU') {
|
|
291
|
-
if (rule.exprVal && rule.exprVal.length
|
|
292
|
-
if (rule.
|
|
293
|
-
|
|
350
|
+
if (rule.exprVal && rule.exprVal.length) {
|
|
351
|
+
if (rule.isMatched === 1) {
|
|
352
|
+
if (!rule.exprVal.includes(paramValue)) {
|
|
353
|
+
if (rule.ruleDesc) {
|
|
354
|
+
return rule.ruleDesc
|
|
355
|
+
}
|
|
356
|
+
return ['WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
if (rule.exprVal.includes(paramValue)) {
|
|
360
|
+
if (rule.ruleDesc) {
|
|
361
|
+
return rule.ruleDesc
|
|
362
|
+
}
|
|
363
|
+
return ['EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
364
|
+
}
|
|
294
365
|
}
|
|
295
|
-
return ['WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
296
366
|
}
|
|
297
367
|
} else if (rule.checkType == 'REGEX') {
|
|
298
368
|
let isPass = false
|
|
@@ -324,6 +394,19 @@ function IsIntOk(fCfgItem, paramValue) {
|
|
|
324
394
|
return null
|
|
325
395
|
}
|
|
326
396
|
function IsObjOk(fCfgItem, paramValue) {
|
|
397
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
398
|
+
return null
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
402
|
+
data == undefined ||
|
|
403
|
+
data == null ||
|
|
404
|
+
data == '' ||
|
|
405
|
+
(typeof data === 'object' && !data.length && !Object.keys(data).length))
|
|
406
|
+
) {
|
|
407
|
+
return null
|
|
408
|
+
}
|
|
409
|
+
|
|
327
410
|
if (!paramValue) {
|
|
328
411
|
return ['NULL_FIELD', fCfgItem.fieldUrl]
|
|
329
412
|
}
|
|
@@ -339,6 +422,19 @@ function IsObjOk(fCfgItem, paramValue) {
|
|
|
339
422
|
return null
|
|
340
423
|
}
|
|
341
424
|
function IsListOk(fCfgItem, paramValue) {
|
|
425
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
426
|
+
return null
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
430
|
+
data == undefined ||
|
|
431
|
+
data == null ||
|
|
432
|
+
data == '' ||
|
|
433
|
+
(typeof data === 'object' && !data.length && !Object.keys(data).length))
|
|
434
|
+
) {
|
|
435
|
+
return null
|
|
436
|
+
}
|
|
437
|
+
|
|
342
438
|
if (!paramValue) {
|
|
343
439
|
return ['NULL_FIELD', fCfgItem.fieldUrl]
|
|
344
440
|
}
|