不要怂,就是干,撸起袖子干!

Commit 2067d2cb by Ruben Bridgewater

Use stricter object comparison (check for !== null)

1 parent ee509090
...@@ -265,7 +265,7 @@ module.exports = (function() { ...@@ -265,7 +265,7 @@ module.exports = (function() {
, i , i
, length; , length;
if (typeof key === 'object') { if (typeof key === 'object' && key !== null) {
values = key; values = key;
options = value || {}; options = value || {};
......
...@@ -537,7 +537,7 @@ module.exports = (function() { ...@@ -537,7 +537,7 @@ module.exports = (function() {
self.scoped = true; self.scoped = true;
// Set defaults // Set defaults
scopeOptions = (typeof lastArg === 'object' && !Array.isArray(lastArg) ? lastArg : {}) || {}; // <-- for no arguments scopeOptions = (typeof lastArg === 'object' && !Array.isArray(lastArg) && lastArg !== null ? lastArg : {}) || {}; // <-- for no arguments
scopeOptions.silent = (scopeOptions !== null && scopeOptions.hasOwnProperty('silent') ? scopeOptions.silent : true); scopeOptions.silent = (scopeOptions !== null && scopeOptions.hasOwnProperty('silent') ? scopeOptions.silent : true);
// Clear out any predefined scopes... // Clear out any predefined scopes...
......
...@@ -31,14 +31,14 @@ SqlString.escapeId = function(val, forbidQualified) { ...@@ -31,14 +31,14 @@ SqlString.escapeId = function(val, forbidQualified) {
}; };
SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) { SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) {
if (arguments.length === 1 && typeof arguments[0] === 'object') { if (arguments.length === 1 && typeof val === 'object' && val !== null) {
val = val.val || val.value || null; val = val.val || val.value || null;
stringifyObjects = val.stringifyObjects || val.objects || undefined; stringifyObjects = val.stringifyObjects || val.objects || undefined;
timeZone = val.timeZone || val.zone || null; timeZone = val.timeZone || val.zone || null;
dialect = val.dialect || null; dialect = val.dialect || null;
field = val.field || null; field = val.field || null;
} }
else if (arguments.length < 3 && typeof arguments[1] === 'object') { else if (arguments.length === 2 && typeof stringifyObjects === 'object' && stringifyObjects !== null) {
timeZone = stringifyObjects.timeZone || stringifyObjects.zone || null; timeZone = stringifyObjects.timeZone || stringifyObjects.zone || null;
dialect = stringifyObjects.dialect || null; dialect = stringifyObjects.dialect || null;
field = stringifyObjects.field || null; field = stringifyObjects.field || null;
...@@ -73,7 +73,7 @@ SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) { ...@@ -73,7 +73,7 @@ SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) {
return SqlString.arrayToList(val, timeZone, dialect, field); return SqlString.arrayToList(val, timeZone, dialect, field);
} }
if (typeof val === 'object') { if (typeof val === 'object' && val !== null) {
if (stringifyObjects) { if (stringifyObjects) {
val = val.toString(); val = val.toString();
} else { } else {
......
...@@ -130,7 +130,7 @@ var Utils = module.exports = { ...@@ -130,7 +130,7 @@ var Utils = module.exports = {
if (merge === true && !!scope.where && !!self.scopeObj.where) { if (merge === true && !!scope.where && !!self.scopeObj.where) {
var scopeKeys = Object.keys(scope.where); var scopeKeys = Object.keys(scope.where);
self.scopeObj.where = self.scopeObj.where.map(function(scopeObj) { self.scopeObj.where = self.scopeObj.where.map(function(scopeObj) {
if (!Array.isArray(scopeObj) && typeof scopeObj === 'object') { if (!Array.isArray(scopeObj) && typeof scopeObj === 'object' && scopeObj !== null) {
return lodash.omit.apply(undefined, [scopeObj].concat(scopeKeys)); return lodash.omit.apply(undefined, [scopeObj].concat(scopeKeys));
} else { } else {
return scopeObj; return scopeObj;
...@@ -270,7 +270,7 @@ var Utils = module.exports = { ...@@ -270,7 +270,7 @@ var Utils = module.exports = {
_where._.bindings = _where._.bindings.concat(values); _where._.bindings = _where._.bindings.concat(values);
} }
} }
else if (typeof where === 'object') { else if (typeof where === 'object' && where !== null) {
// First iteration is trying to compress IN and NOT IN as much as possible... // First iteration is trying to compress IN and NOT IN as much as possible...
// .. reason being is that WHERE username IN (?) AND username IN (?) != WHERE username IN (?,?) // .. reason being is that WHERE username IN (?) AND username IN (?) != WHERE username IN (?,?)
Object.keys(where).forEach(function(i) { Object.keys(where).forEach(function(i) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!