xzwebx-httpfilter 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/HttpFilter.js +26 -105
  2. package/package.json +1 -1
package/HttpFilter.js CHANGED
@@ -185,6 +185,17 @@ function cycleCheckParams(msgFieldMap, data) {
185
185
  }
186
186
  return null
187
187
  }
188
+
189
+ function getCustomTips(tips) {
190
+ if (tips.length > 3 && tips.substring(0, 2) === '${' && tips.substring(tips.length -1, tips.length) === '}') {
191
+ let tipsKey = tips.substring(2, tips.length -1)
192
+ tipsKey = tipsKey.trim()
193
+ if (TipsMap[tipsKey]) {
194
+ return TipsMap[tipsKey].tips
195
+ }
196
+ }
197
+ return tips
198
+ }
188
199
  function IsStringOk(fCfgItem, paramValue) {
189
200
  if (!fCfgItem || !fCfgItem.ifMust) {
190
201
  return null
@@ -201,13 +212,7 @@ function IsStringOk(fCfgItem, paramValue) {
201
212
 
202
213
  if (!paramValue || typeof paramValue != 'string') {
203
214
  if (fCfgItem.nullTips) {
204
- if (fCfgItem.nullTips.substring(0, 2) === '${' && fCfgItem.nullTips.substring(fCfgItem.nullTips.length -1, fCfgItem.nullTips.length) === '}') {
205
- let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
206
- if (TipsMap[nullTipsKey]) {
207
- return TipsMap[nullTipsKey].tips
208
- }
209
- }
210
- return fCfgItem.nullTips
215
+ return getCustomTips(fCfgItem.nullTips)
211
216
  }
212
217
  return ['WEBX_NULL_FIELD', 'string', fCfgItem.fieldUrl]
213
218
  }
@@ -231,13 +236,7 @@ function IsStringOk(fCfgItem, paramValue) {
231
236
 
232
237
  if (!isPass) {
233
238
  if (rule.ruleDesc) {
234
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
235
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
236
- if (TipsMap[ruleTipsKey]) {
237
- return TipsMap[ruleTipsKey].tips
238
- }
239
- }
240
- return rule.ruleDesc
239
+ return getCustomTips(rule.ruleDesc)
241
240
  }
242
241
  return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
243
242
  }
@@ -247,26 +246,14 @@ function IsStringOk(fCfgItem, paramValue) {
247
246
  if (rule.isMatched === 1) {
248
247
  if (!rule.exprVal.includes(paramValue)) {
249
248
  if (rule.ruleDesc) {
250
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
251
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
252
- if (TipsMap[ruleTipsKey]) {
253
- return TipsMap[ruleTipsKey].tips
254
- }
255
- }
256
- return rule.ruleDesc
249
+ return getCustomTips(rule.ruleDesc)
257
250
  }
258
251
  return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
259
252
  }
260
253
  } else {
261
254
  if (rule.exprVal.includes(paramValue)) {
262
255
  if (rule.ruleDesc) {
263
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
264
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
265
- if (TipsMap[ruleTipsKey]) {
266
- return TipsMap[ruleTipsKey].tips
267
- }
268
- }
269
- return rule.ruleDesc
256
+ return getCustomTips(rule.ruleDesc)
270
257
  }
271
258
  return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
272
259
  }
@@ -290,13 +277,7 @@ function IsStringOk(fCfgItem, paramValue) {
290
277
  }
291
278
  if (!isPass) {
292
279
  if (rule.ruleDesc) {
293
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
294
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
295
- if (TipsMap[ruleTipsKey]) {
296
- return TipsMap[ruleTipsKey].tips
297
- }
298
- }
299
- return rule.ruleDesc
280
+ return getCustomTips(rule.ruleDesc)
300
281
  }
301
282
  if (rule.isMatched === 1) {
302
283
  return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
@@ -325,13 +306,7 @@ function IsStringOk(fCfgItem, paramValue) {
325
306
  }
326
307
  if (!isPass) {
327
308
  if (rule.ruleDesc) {
328
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
329
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
330
- if (TipsMap[ruleTipsKey]) {
331
- return TipsMap[ruleTipsKey].tips
332
- }
333
- }
334
- return rule.ruleDesc
309
+ return getCustomTips(rule.ruleDesc)
335
310
  }
336
311
  return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
337
312
  }
@@ -356,13 +331,7 @@ function IsIntOk(fCfgItem, paramValue) {
356
331
 
357
332
  if (paramValue == undefined || typeof paramValue != 'number') {
358
333
  if (fCfgItem.nullTips) {
359
- if (fCfgItem.nullTips.substring(0, 2) === '${' && fCfgItem.nullTips.substring(fCfgItem.nullTips.length -1, fCfgItem.nullTips.length) === '}') {
360
- let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
361
- if (TipsMap[nullTipsKey]) {
362
- return TipsMap[nullTipsKey].tips
363
- }
364
- }
365
- return fCfgItem.nullTips
334
+ return getCustomTips(fCfgItem.nullTips)
366
335
  }
367
336
  return ['WEBX_NULL_FIELD', 'number', fCfgItem.fieldUrl]
368
337
  }
@@ -386,13 +355,7 @@ function IsIntOk(fCfgItem, paramValue) {
386
355
 
387
356
  if (!isPass) {
388
357
  if (rule.ruleDesc) {
389
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
390
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
391
- if (TipsMap[ruleTipsKey]) {
392
- return TipsMap[ruleTipsKey].tips
393
- }
394
- }
395
- return rule.ruleDesc
358
+ return getCustomTips(rule.ruleDesc)
396
359
  }
397
360
  return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
398
361
  }
@@ -401,26 +364,14 @@ function IsIntOk(fCfgItem, paramValue) {
401
364
  if (rule.isMatched === 1) {
402
365
  if (!rule.exprVal.includes(paramValue)) {
403
366
  if (rule.ruleDesc) {
404
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
405
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
406
- if (TipsMap[ruleTipsKey]) {
407
- return TipsMap[ruleTipsKey].tips
408
- }
409
- }
410
- return rule.ruleDesc
367
+ return getCustomTips(rule.ruleDesc)
411
368
  }
412
369
  return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
413
370
  }
414
371
  } else {
415
372
  if (rule.exprVal.includes(paramValue)) {
416
373
  if (rule.ruleDesc) {
417
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
418
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
419
- if (TipsMap[ruleTipsKey]) {
420
- return TipsMap[ruleTipsKey].tips
421
- }
422
- }
423
- return rule.ruleDesc
374
+ return getCustomTips(rule.ruleDesc)
424
375
  }
425
376
  return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
426
377
  }
@@ -446,13 +397,7 @@ function IsIntOk(fCfgItem, paramValue) {
446
397
  }
447
398
  if (!isPass) {
448
399
  if (rule.ruleDesc) {
449
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
450
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
451
- if (TipsMap[ruleTipsKey]) {
452
- return TipsMap[ruleTipsKey].tips
453
- }
454
- }
455
- return rule.ruleDesc
400
+ return getCustomTips(rule.ruleDesc)
456
401
  }
457
402
  return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
458
403
  }
@@ -477,13 +422,7 @@ function IsObjOk(fCfgItem, paramValue) {
477
422
 
478
423
  if (!paramValue || paramValue.constructor != Object || !Object.keys(paramValue).length) {
479
424
  if (fCfgItem.nullTips) {
480
- if (fCfgItem.nullTips.substring(0, 2) === '${' && fCfgItem.nullTips.substring(fCfgItem.nullTips.length -1, fCfgItem.nullTips.length) === '}') {
481
- let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
482
- if (TipsMap[nullTipsKey]) {
483
- return TipsMap[nullTipsKey].tips
484
- }
485
- }
486
- return fCfgItem.nullTips
425
+ return getCustomTips(fCfgItem.nullTips)
487
426
  }
488
427
  return ['WEBX_NULL_FIELD', 'map', fCfgItem.fieldUrl]
489
428
  }
@@ -508,13 +447,7 @@ function IsObjOk(fCfgItem, paramValue) {
508
447
 
509
448
  if (!isPass) {
510
449
  if (rule.ruleDesc) {
511
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
512
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
513
- if (TipsMap[ruleTipsKey]) {
514
- return TipsMap[ruleTipsKey].tips
515
- }
516
- }
517
- return rule.ruleDesc
450
+ return getCustomTips(rule.ruleDesc)
518
451
  }
519
452
  return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
520
453
  }
@@ -539,13 +472,7 @@ function IsListOk(fCfgItem, paramValue) {
539
472
 
540
473
  if (!paramValue || paramValue.constructor != Array || !paramValue.length) {
541
474
  if (fCfgItem.nullTips) {
542
- if (fCfgItem.nullTips.substring(0, 2) === '${' && fCfgItem.nullTips.substring(fCfgItem.nullTips.length -1, fCfgItem.nullTips.length) === '}') {
543
- let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
544
- if (TipsMap[nullTipsKey]) {
545
- return TipsMap[nullTipsKey].tips
546
- }
547
- }
548
- return fCfgItem.nullTips
475
+ return getCustomTips(fCfgItem.nullTips)
549
476
  }
550
477
  return ['WEBX_NULL_FIELD', 'list', fCfgItem.fieldUrl]
551
478
  }
@@ -570,13 +497,7 @@ function IsListOk(fCfgItem, paramValue) {
570
497
 
571
498
  if (!isPass) {
572
499
  if (rule.ruleDesc) {
573
- if (rule.ruleDesc.substring(0, 2) === '${' && rule.ruleDesc.substring(rule.ruleDesc.length -1, rule.ruleDesc.length) === '}') {
574
- let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
575
- if (TipsMap[ruleTipsKey]) {
576
- return TipsMap[ruleTipsKey].tips
577
- }
578
- }
579
- return rule.ruleDesc
500
+ return getCustomTips(rule.ruleDesc)
580
501
  }
581
502
  return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
582
503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xzwebx-httpfilter",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "main": "HttpFilter.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"