From 8970115e428fa057cf50a3ad873a5664a04fc67c Mon Sep 17 00:00:00 2001 From: "Min H. Hong" Date: Thu, 7 May 2026 15:54:54 +0900 Subject: [PATCH 1/4] Update connection.cc --- src/connection.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/connection.cc b/src/connection.cc index 0285b3a..15a8eae 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); From 891616cd87518a2c4ee1d7ba91a159a66d2aea74 Mon Sep 17 00:00:00 2001 From: "Min H. Hong" Date: Fri, 8 May 2026 13:27:45 +0900 Subject: [PATCH 2/4] Fix missing closing parenthesis in buffer check --- src/connection.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection.cc b/src/connection.cc index 15a8eae..26904d6 100644 --- a/src/connection.cc +++ b/src/connection.cc @@ -656,7 +656,7 @@ NAN_METHOD(Connection::PutCopyData) { Connection* self = NODE_THIS(); - if (!node::Buffer::HasInstance(info[0]) { + if (!node::Buffer::HasInstance(info[0])) { return Nan::ThrowTypeError("First argument must be a Buffer"); } From 469ce9f85965d458a417976b3b8e71ee96bc1e64 Mon Sep 17 00:00:00 2001 From: "Min H. Hong" Date: Fri, 8 May 2026 13:30:09 +0900 Subject: [PATCH 3/4] Add TypeError test for putCopyData method Add test for TypeError when non-Buffer is passed to putCopyData --- test/copy-in.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/copy-in.js b/test/copy-in.js index 9940be3..6e9fcde 100644 --- a/test/copy-in.js +++ b/test/copy-in.js @@ -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; + }); + }); }); From 44908448d73c42673fc13e212e31849993f7ac88 Mon Sep 17 00:00:00 2001 From: "Min H. Hong" Date: Fri, 8 May 2026 14:24:35 +0900 Subject: [PATCH 4/4] Fix typo in test description for data assumptions --- test/copy-in.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/copy-in.js b/test/copy-in.js index 6e9fcde..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); });