Skip to content

Commit

Permalink
Don't ignore undefined keys in where clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Mar 22, 2019
1 parent cc758f4 commit e518578
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
[![StackOverflow (waterline)](https://img.shields.io/badge/stackoverflow-waterline-blue.svg)]( http://stackoverflow.com/questions/tagged/waterline)
[![StackOverflow (sails)](https://img.shields.io/badge/stackoverflow-sails.js-blue.svg)]( http://stackoverflow.com/questions/tagged/sails.js)

# This Fork

This fork of Waterline changes the following behaviour:

* an Error is thrown if an `undefined` value is passed to a `WHERE` clause. This change is debated at https://github.com/balderdashy/sails/issues/4639, but currently unresolved

# Introduction

Waterline is a next-generation storage and retrieval engine, and the default ORM used in the [Sails framework](https://sailsjs.com).

It provides a uniform API for accessing stuff from different kinds of [databases and protocols](https://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters). That means you write the same code to get and store things like users, whether they live in MySQL, MongoDB, neDB, or Postgres.
Expand Down
9 changes: 3 additions & 6 deletions lib/waterline/utils/query/private/normalize-where-clause.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,10 @@ module.exports = function normalizeWhereClause(whereClause, modelIdentity, orm,
// > here, we have to be more forgiving-- both for usability and backwards-compatibility.


// ╔═╗╔╦╗╦═╗╦╔═╗ ╦╔═╔═╗╦ ╦╔═╗ ┬ ┬┬┌┬┐┬ ┬ ╦ ╦╔╗╔╔╦╗╔═╗╔═╗╦╔╗╔╔═╗╔╦╗ ┬─┐┬ ┬┌─┐
// ╚═╗ ║ ╠╦╝║╠═╝ ╠╩╗║╣ ╚╦╝╚═╗ ││││ │ ├─┤ ║ ║║║║ ║║║╣ ╠╣ ║║║║║╣ ║║ ├┬┘├─┤└─┐
// ╚═╝ ╩ ╩╚═╩╩ ╩ ╩╚═╝ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ╚═╝╝╚╝═╩╝╚═╝╚ ╩╝╚╝╚═╝═╩╝ ┴└─┴ ┴└─┘
// Strip out any keys with undefined values.
// Convert undefined keys to null
_.each(_.keys(branch), function (key){
if (_.isUndefined(branch[key])) {
delete branch[key];
throw flaverr('E_CONSTRAINT_WOULD_MATCH_NOTHING', new Error(`Unexpected undefined value in WHERE clause for column: ${key}`));
}
});

Expand Down Expand Up @@ -600,7 +597,7 @@ module.exports = function normalizeWhereClause(whereClause, modelIdentity, orm,

// Recursive call
try {
_recursiveStep(conjunctOrDisjunct, recursionDepth+1, conjunctsOrDisjuncts, i, soleBranchKey === 'or');
_recursiveStep(conjunctOrDisjunct, recursionDepth+1, conjunctsOrDisjuncts, i);
} catch (e) {
switch (e.code) {

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "waterline",
"name": "safe-waterline",
"description": "An ORM for Node.js and the Sails framework",
"version": "0.13.5-0",
"homepage": "http://waterlinejs.org",
"contributors": [
{
"name": "seerepo",
"github": "https://github.com/balderdashy/waterline/graphs/contributors"
"github": "https://github.com/alxndrsn/waterline/graphs/contributors"
}
],
"dependencies": {
Expand Down Expand Up @@ -37,7 +37,7 @@
"sails",
"sails.js"
],
"repository": "git://github.com/balderdashy/waterline.git",
"repository": "git://github.com/alxndrsn/waterline.git",
"main": "./lib/waterline",
"scripts": {
"test": "nodever=`node -e \"console.log('\\`node -v\\`'[1]);\"` && if [ $nodever != \"0\" ]; then npm run lint; fi && npm run custom-tests",
Expand Down

0 comments on commit e518578

Please sign in to comment.