Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed boolean casting method to not cast incorrect values #1225

Merged
merged 1 commit into from
Jan 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/waterline/core/typecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/core.cast/cast.boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down