@@ -54,6 +54,10 @@ module.exports = function(app) {
54
54
55
55
} ;
56
56
57
+ function isString ( s ) {
58
+ if ( null == s ) return false ;
59
+ return 'string' == typeof ( s ) ?true :false
60
+ }
57
61
58
62
var v = require ( 'validator' ) ;
59
63
@@ -148,13 +152,13 @@ Validator.prototype.ensure = function(assertion, tip, shouldBail) {
148
152
} ;
149
153
150
154
Validator . prototype . isInt = function ( tip ) {
151
- if ( this . goOn && ( "number" != typeof this . value && ! v . isInt ( this . value ) ) ) {
155
+ if ( this . goOn && ( "number" != typeof this . value && ( ! isString ( this . value ) || ! v . isInt ( this . value ) ) ) ) {
152
156
this . addError ( tip || this . key + " is not integer." ) ;
153
157
}
154
158
return this ;
155
159
} ;
156
160
Validator . prototype . isFloat = function ( tip ) {
157
- if ( this . goOn && ( "number" != typeof this . value && ! v . isFloat ( this . value ) ) ) {
161
+ if ( this . goOn && ( "number" != typeof this . value && ( ! isString ( this . value ) || ! v . isFloat ( this . value ) ) ) ) {
158
162
this . addError ( tip || this . key + " is not float." ) ;
159
163
}
160
164
return this ;
@@ -227,92 +231,92 @@ Validator.prototype.le = function(l, tip) {
227
231
return this ;
228
232
} ;
229
233
Validator . prototype . contains = function ( s , tip ) {
230
- if ( this . goOn && ! v . contains ( this . value , s ) ) {
234
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . contains ( this . value , s ) ) ) {
231
235
this . addError ( tip || this . key + " is must contain " + s + "." ) ;
232
236
}
233
237
return this ;
234
238
} ;
235
239
Validator . prototype . notContains = function ( s , tip ) {
236
- if ( this . goOn && v . contains ( this . value , s ) ) {
240
+ if ( this . goOn && ( ! isString ( this . value ) || v . contains ( this . value , s ) ) ) {
237
241
this . addError ( tip || this . key + " is must not contain " + s + "." ) ;
238
242
}
239
243
return this ;
240
244
} ;
241
245
Validator . prototype . isEmail = function ( tip , options ) {
242
- if ( this . goOn && ! v . isEmail ( this . value , options ) ) {
246
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isEmail ( this . value , options ) ) ) {
243
247
this . addError ( tip || this . key + " is not email format." ) ;
244
248
}
245
249
return this ;
246
250
} ;
247
251
Validator . prototype . isUrl = function ( tip , options ) {
248
- if ( this . goOn && ! v . isURL ( this . value , options ) ) {
252
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isURL ( this . value , options ) ) ) {
249
253
this . addError ( tip || this . key + " is not url format." ) ;
250
254
}
251
255
return this ;
252
256
} ;
253
257
Validator . prototype . isIp = function ( tip , version ) {
254
- if ( this . goOn && ! v . isIP ( this . value , version ) ) {
258
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isIP ( this . value , version ) ) ) {
255
259
this . addError ( tip || this . key + " is not ip format." ) ;
256
260
}
257
261
return this ;
258
262
} ;
259
263
Validator . prototype . isAlpha = function ( tip , locale ) {
260
- if ( this . goOn && ! v . isAlpha ( this . value , locale ) ) {
264
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isAlpha ( this . value , locale ) ) ) {
261
265
this . addError ( tip || this . key + " is not an alpha string." ) ;
262
266
}
263
267
return this ;
264
268
} ;
265
269
Validator . prototype . isNumeric = function ( tip ) {
266
- if ( this . goOn && ! v . isNumeric ( this . value ) ) {
270
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isNumeric ( this . value ) ) ) {
267
271
this . addError ( tip || this . key + " is not numeric." ) ;
268
272
}
269
273
return this ;
270
274
} ;
271
275
272
276
Validator . prototype . isAlphanumeric = function ( tip , locale ) {
273
- if ( this . goOn && ! v . isAlphanumeric ( this . value , locale ) ) {
277
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isAlphanumeric ( this . value , locale ) ) ) {
274
278
this . addError ( tip || this . key + " is not an aphanumeric string." ) ;
275
279
}
276
280
return this ;
277
281
} ;
278
282
Validator . prototype . isBase64 = function ( tip ) {
279
- if ( this . goOn && ! v . isBase64 ( this . value ) ) {
283
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isBase64 ( this . value ) ) ) {
280
284
this . addError ( tip || this . key + " is not a base64 string." ) ;
281
285
}
282
286
return this ;
283
287
} ;
284
288
Validator . prototype . isHexadecimal = function ( tip ) {
285
- if ( this . goOn && ! v . isHexadecimal ( this . value ) ) {
289
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isHexadecimal ( this . value ) ) ) {
286
290
this . addError ( tip || this . key + " is not a hexa decimal string." ) ;
287
291
}
288
292
return this ;
289
293
} ;
290
294
Validator . prototype . isHexColor = function ( tip ) {
291
- if ( this . goOn && ! v . isHexColor ( this . value ) ) {
295
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isHexColor ( this . value ) ) ) {
292
296
this . addError ( tip || this . key + " is not hex color format." ) ;
293
297
}
294
298
return this ;
295
299
} ;
296
300
Validator . prototype . isLowercase = function ( tip ) {
297
- if ( this . goOn && ! v . isLowercase ( this . value ) ) {
301
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isLowercase ( this . value ) ) ) {
298
302
this . addError ( tip || this . key + " is not a lowwer case string" ) ;
299
303
}
300
304
return this ;
301
305
} ;
302
306
Validator . prototype . isUppercase = function ( tip ) {
303
- if ( this . goOn && ! v . isUppercase ( this . value ) ) {
307
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isUppercase ( this . value ) ) ) {
304
308
this . addError ( tip || this . key + " is not a upper case string." ) ;
305
309
}
306
310
return this ;
307
311
} ;
308
312
Validator . prototype . isDivisibleBy = function ( n , tip ) {
309
- if ( this . goOn && ! v . isDivisibleBy ( this . value , n ) ) {
313
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isDivisibleBy ( this . value , n ) ) ) {
310
314
this . addError ( tip || this . key + " can not divide by" + n + "." ) ;
311
315
}
312
316
return this ;
313
317
} ;
314
318
Validator . prototype . isNull = function ( tip ) {
315
- if ( this . goOn && ! v . isNull ( this . value ) ) {
319
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isNull ( this . value ) ) ) {
316
320
this . addError ( tip || this . key + " is not null." ) ;
317
321
}
318
322
return this ;
@@ -333,13 +337,13 @@ Validator.prototype.isByteLength = function(min, max,charset,tip) {
333
337
} ;
334
338
Validator . prototype . byteLength = Validator . prototype . isByteLength ;
335
339
Validator . prototype . isUUID = function ( tip , ver ) {
336
- if ( this . goOn && ! v . isUUID ( this . value , ver ) ) {
340
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isUUID ( this . value , ver ) ) ) {
337
341
this . addError ( tip || this . key + " is not a UUID format." ) ;
338
342
}
339
343
return this ;
340
344
} ;
341
345
Validator . prototype . isDate = function ( tip ) {
342
- if ( this . goOn && ! util . isDate ( this . value ) && ! v . isDate ( this . value ) ) {
346
+ if ( this . goOn && ! util . isDate ( this . value ) && ( ! isString ( this . value ) || ! v . isDate ( this . value ) ) ) {
343
347
this . addError ( tip || this . key + " is not a date format." ) ;
344
348
}
345
349
return this ;
@@ -353,111 +357,111 @@ Validator.prototype.isTime = function(tip) {
353
357
} ;
354
358
355
359
Validator . prototype . isAfter = function ( d , tip ) {
356
- if ( this . goOn && ! v . isAfter ( this . value , d ) ) {
360
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isAfter ( this . value , d ) ) ) {
357
361
this . addError ( tip || this . key + " must after " + d + "." ) ;
358
362
}
359
363
return this ;
360
364
} ;
361
365
Validator . prototype . isBefore = function ( d , tip ) {
362
- if ( this . goOn && ! v . isBefore ( this . value , d ) ) {
366
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isBefore ( this . value , d ) ) ) {
363
367
this . addError ( tip || this . key + " must before " + d + "." ) ;
364
368
}
365
369
return this ;
366
370
} ;
367
371
Validator . prototype . isCreditCard = function ( tip ) {
368
- if ( this . goOn && ! v . isCreditCard ( this . value ) ) {
372
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isCreditCard ( this . value ) ) ) {
369
373
this . addError ( tip || this . key + " is not credit card format." ) ;
370
374
}
371
375
return this ;
372
376
} ;
373
377
Validator . prototype . isISBN = function ( tip , version ) {
374
- if ( this . goOn && ! v . isISBN ( this . value , version ) ) {
378
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isISBN ( this . value , version ) ) ) {
375
379
this . addError ( tip || this . key + " is not a ISBN format." ) ;
376
380
}
377
381
return this ;
378
382
} ;
379
383
Validator . prototype . isJSON = function ( tip ) {
380
- if ( this . goOn && ! v . isJSON ( this . value ) ) {
384
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isJSON ( this . value ) ) ) {
381
385
this . addError ( tip || this . key + " is not a json format." ) ;
382
386
}
383
387
return this ;
384
388
} ;
385
389
386
390
Validator . prototype . isMultibyte = function ( tip ) {
387
- if ( this . goOn && ! v . isMultibyte ( this . value ) ) {
391
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isMultibyte ( this . value ) ) ) {
388
392
this . addError ( tip || this . key + " is not a multibyte string." ) ;
389
393
}
390
394
return this ;
391
395
} ;
392
396
Validator . prototype . isAscii = function ( tip ) {
393
- if ( this . goOn && ! v . isAscii ( this . value ) ) {
397
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isAscii ( this . value ) ) ) {
394
398
this . addError ( tip || this . key + " is not a ascii string." ) ;
395
399
}
396
400
return this ;
397
401
} ;
398
402
Validator . prototype . isFullWidth = function ( tip ) {
399
- if ( this . goOn && ! v . isFullWidth ( this . value ) ) {
403
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isFullWidth ( this . value ) ) ) {
400
404
this . addError ( tip || this . key + " is not a full width string." ) ;
401
405
}
402
406
return this ;
403
407
} ;
404
408
Validator . prototype . isHalfWidth = function ( tip ) {
405
- if ( this . goOn && ! v . isHalfWidth ( this . value ) ) {
409
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isHalfWidth ( this . value ) ) ) {
406
410
this . addError ( tip || this . key + " is not a half width string." ) ;
407
411
}
408
412
return this ;
409
413
} ;
410
414
Validator . prototype . isVariableWidth = function ( tip ) {
411
- if ( this . goOn && ! v . isVariableWidth ( this . value ) ) {
415
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isVariableWidth ( this . value ) ) ) {
412
416
this . addError ( tip || this . key + " is not a variable width string." ) ;
413
417
}
414
418
return this ;
415
419
} ;
416
420
Validator . prototype . isSurrogatePair = function ( tip ) {
417
- if ( this . goOn && ! v . isSurrogatePair ( this . value ) ) {
421
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isSurrogatePair ( this . value ) ) ) {
418
422
this . addError ( tip || this . key + " is not a surrogate pair string." ) ;
419
423
}
420
424
return this ;
421
425
} ;
422
426
Validator . prototype . isCurrency = function ( tip , options ) {
423
- if ( this . goOn && ! v . isCurrency ( this . value , options ) ) {
427
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isCurrency ( this . value , options ) ) ) {
424
428
this . addError ( tip || this . key + " is not a currency format." ) ;
425
429
}
426
430
return this ;
427
431
} ;
428
432
Validator . prototype . isDataURI = function ( tip ) {
429
- if ( this . goOn && ! v . isDataURI ( this . value ) ) {
433
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isDataURI ( this . value ) ) ) {
430
434
this . addError ( tip || this . key + " is not a data uri format." ) ;
431
435
}
432
436
return this ;
433
437
} ;
434
438
Validator . prototype . isMobilePhone = function ( tip , locale ) {
435
- if ( this . goOn && ! v . isMobilePhone ( this . value , locale ) ) {
439
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isMobilePhone ( this . value , locale ) ) ) {
436
440
this . addError ( tip || this . key + " is not a mobile phone format." ) ;
437
441
}
438
442
return this ;
439
443
} ;
440
444
Validator . prototype . isISO8601 = function ( tip ) {
441
- if ( this . goOn && ! v . isISO8601 ( this . value ) ) {
445
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isISO8601 ( this . value ) ) ) {
442
446
this . addError ( tip || this . key + " is not a ISO8601 string format." ) ;
443
447
}
444
448
return this ;
445
449
} ;
446
450
Validator . prototype . isMACAddress = function ( tip ) {
447
- if ( this . goOn && ! v . isMACAddress ( this . value ) ) {
451
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isMACAddress ( this . value ) ) ) {
448
452
this . addError ( tip || this . key + " is not a MAC address format." ) ;
449
453
}
450
454
return this ;
451
455
} ;
452
456
453
457
Validator . prototype . isISIN = function ( tip ) {
454
- if ( this . goOn && ! v . isISIN ( this . value ) ) {
458
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isISIN ( this . value ) ) ) {
455
459
this . addError ( tip || this . key + " is not a ISIN format." ) ;
456
460
}
457
461
return this ;
458
462
} ;
459
463
Validator . prototype . isFQDN = function ( tip , options ) {
460
- if ( this . goOn && ! v . isFQDN ( this . value , options ) ) {
464
+ if ( this . goOn && ( ! isString ( this . value ) || ! v . isFQDN ( this . value , options ) ) ) {
461
465
this . addError ( tip || this . key + " is not a fully qualified domain name format." ) ;
462
466
}
463
467
return this ;
0 commit comments