diff --git a/lib/query.js b/lib/query.js index e294a4f0..a8e76547 100644 --- a/lib/query.js +++ b/lib/query.js @@ -127,6 +127,12 @@ Query.prototype.handleError = function(err, connection) { }; Query.prototype.submit = function(connection) { + if (typeof this.text != 'string' && typeof this.name != 'string') { + const err = new Error('A query must have either text or a name. Supplying neither is unsupported.') + connection.emit('error', err) + connection.emit('readyForQuery') + return + } if(this.requiresPreparation()) { this.prepare(connection); } else { diff --git a/test/integration/client/error-handling-tests.js b/test/integration/client/error-handling-tests.js index 89c181a5..c929dd7b 100644 --- a/test/integration/client/error-handling-tests.js +++ b/test/integration/client/error-handling-tests.js @@ -159,3 +159,16 @@ suite.test('connected, idle client error', (done) => { client.end(done) }) }) + +suite.test('cannot pass non-string values to query as text', (done) => { + const client = new Client() + client.connect() + client.query({ text: { } }, (err) => { + assert(err) + client.query({ }, (err) => { + client.on('drain', () => { + client.end(done) + }) + }) + }) +})