From ddeb0b573d0fac03d80a9afa0a4819becc8a4806 Mon Sep 17 00:00:00 2001 From: Eduardo Pereira de Sousa Date: Wed, 18 Nov 2015 17:21:22 -0200 Subject: [PATCH] Changed boolean casting method to not cast incorrect values --- lib/waterline/core/typecast.js | 6 ++---- test/unit/core/core.cast/cast.boolean.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/waterline/core/typecast.js b/lib/waterline/core/typecast.js index a90bdebda..55b6bf9ea 100644 --- a/lib/waterline/core/typecast.js +++ b/lib/waterline/core/typecast.js @@ -178,7 +178,7 @@ Cast.prototype.boolean = function boolean(value) { if (_.isString(value)) { if (value === 'true') return true; if (value === 'false') return false; - return false; + return value; } // Nicely cast [0, 1] to true and false @@ -191,9 +191,7 @@ Cast.prototype.boolean = function boolean(value) { if (parsed === 0) return false; if (parsed === 1) return true; - if (value === true || value === false) return value; - - return false; + return value; }; /** diff --git a/test/unit/core/core.cast/cast.boolean.js b/test/unit/core/core.cast/cast.boolean.js index 43a470711..5170909ad 100644 --- a/test/unit/core/core.cast/cast.boolean.js +++ b/test/unit/core/core.cast/cast.boolean.js @@ -42,9 +42,9 @@ describe('Core Type Casting', function() { assert(values.name === false); }); - it('should default to false', function() { + it('should not cast bad values', function() { var values = person._cast.run({ name: 'foo' }); - assert(values.name === false); + assert(values.name === 'foo'); }); it('should cast integer 0 to a boolean', function() {