diff --git a/src/connection.cc b/src/connection.cc index 0285b3a..26904d6 100644 --- a/src/connection.cc +++ b/src/connection.cc @@ -656,6 +656,10 @@ NAN_METHOD(Connection::PutCopyData) { Connection* self = NODE_THIS(); + if (!node::Buffer::HasInstance(info[0])) { + return Nan::ThrowTypeError("First argument must be a Buffer"); + } + v8::Local buffer = info[0].As(); char* data = node::Buffer::Data(buffer); diff --git a/test/copy-in.js b/test/copy-in.js index 9940be3..df2a2ba 100644 --- a/test/copy-in.js +++ b/test/copy-in.js @@ -5,7 +5,7 @@ var bufferFrom = require('buffer-from') describe('COPY IN', function() { helper.setupIntegration(); - it('check existing data assuptions', function() { + it('check existing data assumptions', function() { this.pq.exec('SELECT COUNT(*) FROM test_data'); assert.equal(this.pq.getvalue(0, 0), 3); }); @@ -45,4 +45,12 @@ describe('COPY IN', function() { this.pq.exec('SELECT COUNT(*) FROM test_data'); assert.equal(this.pq.getvalue(0, 0), 4); }); + + it('throws TypeError when non-Buffer is passed to putCopyData', function() { + assert.throws(function() { + this.pq.$putCopyData("not a buffer"); + }.bind(this), function(err) { + return err instanceof TypeError; + }); + }); });