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

1227: add assertion for basic where clause values #5417

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

# 2.3.0 - 31 August, 2022

### Bug fixes
- Add assertion for basic where clause not to be object or array #1227

littlemaneuver marked this conversation as resolved.
Show resolved Hide resolved
### New features:

- PostgreSQL: Explicit jsonb support for custom pg clients #5201
Expand Down
5 changes: 5 additions & 0 deletions lib/query/querybuilder.js
Expand Up @@ -441,6 +441,11 @@ class Builder extends EventEmitter {
}
}

assert(
!isObject(value),
'The values in where clause must not be object or array.'
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1227 still applies if value is 0 the integer.

Adding value.toString() instead of value when pushing onto the where statement stack should solve the issue.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean value false , if not passed as a string, yields the same result (talking about MySQL here, don't know whether it applies to #1227 ) https://www.db-fiddle.com/f/w8CJ5SAYEKwJqAXyoYPSwC/2


// Push onto the where statement stack.
this._statements.push({
grouping: 'where',
Expand Down
28 changes: 28 additions & 0 deletions test/unit/query/builder.js
Expand Up @@ -848,6 +848,34 @@ describe('QueryBuilder', () => {
});
});

it('basic wheres should not accept array or object as a value', () => {
try {
clientsWithCustomLoggerForTestWarnings.pg
.queryBuilder()
.select('*')
.from('users')
.where('id', '=', [0]);
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}

try {
clientsWithCustomLoggerForTestWarnings.pg
.queryBuilder()
.select('*')
.from('users')
.where({ id: { test: 'test' } });
throw new Error('Should not reach this point');
} catch (error) {
expect(error.message).to.equal(
'The values in where clause must not be object or array.'
);
}
});

it('uses whereLike, #2265', () => {
testsql(qb().select('*').from('users').whereLike('name', 'luk%'), {
mysql: {
Expand Down