From 04d8b45e061b2e8b1275441640737247779ff290 Mon Sep 17 00:00:00 2001 From: Rusty Bailey Date: Thu, 17 Sep 2015 22:06:19 -0400 Subject: [PATCH] Fix #435: Convert returned comparison in isBefore() to a boolean. --- test/validators.js | 10 ++++++++++ validator.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 6590c766b..959ba1dbd 100644 --- a/test/validators.js +++ b/test/validators.js @@ -876,6 +876,11 @@ describe('Validators', function () { test({ validator: 'isAfter', valid: [ '2100-08-04', new Date(Date.now() + 86400000) ], invalid: [ '2010-07-02', new Date(0) ] }); + test({ validator: 'isAfter', args: ['2011-08-03'], + valid: [ '2015-09-17' ], + invalid: [ 'invalid date' ] }); + test({ validator: 'isAfter', args: ['invalid date'], + invalid: [ 'invalid date', '2015-09-17' ] }); }); it('should validate dates against an end date', function () { @@ -888,6 +893,11 @@ describe('Validators', function () { test({ validator: 'isBefore', valid: [ '2000-08-04', new Date(0), new Date(Date.now() - 86400000) ], invalid: [ '2100-07-02', new Date(2017, 10, 10) ] }); + test({ validator: 'isBefore', args: ['2011-08-03'], + valid: [ '1999-12-31' ], + invalid: [ 'invalid date' ] }); + test({ validator: 'isBefore', args: ['invalid date'], + invalid: [ 'invalid date', '1999-12-31' ] }); }); it('should validate that integer strings are divisible by a number', function () { diff --git a/validator.js b/validator.js index 81bcc65b4..76f812bc6 100644 --- a/validator.js +++ b/validator.js @@ -480,7 +480,7 @@ validator.isBefore = function (str, date) { var comparison = validator.toDate(date || new Date()) , original = validator.toDate(str); - return original && comparison && original < comparison; + return !!(original && comparison && original < comparison); }; validator.isIn = function (str, options) {