From ca4ac9983aab7844ed5f068b8900052e1cd09652 Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Sun, 16 Jul 2017 16:39:22 -0500 Subject: [PATCH] Re-implement other patch --- lib/utils.js | 14 ++++++++------ test/unit/utils-tests.js | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index a83cdee9..166cbddc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -32,6 +32,8 @@ function arrayString (val) { result = result + 'NULL' } else if (Array.isArray(val[i])) { result = result + arrayString(val[i]) + } else if (val[i] instanceof Buffer) { + result += '\\\\x' + val[i].toString('hex') } else { result += escapeElement(prepareValue(val[i])) } @@ -106,12 +108,12 @@ function dateToString (date) { function dateToStringUTC (date) { var ret = pad(date.getUTCFullYear(), 4) + '-' + - pad(date.getUTCMonth() + 1, 2) + '-' + - pad(date.getUTCDate(), 2) + 'T' + - pad(date.getUTCHours(), 2) + ':' + - pad(date.getUTCMinutes(), 2) + ':' + - pad(date.getUTCSeconds(), 2) + '.' + - pad(date.getUTCMilliseconds(), 3) + pad(date.getUTCMonth() + 1, 2) + '-' + + pad(date.getUTCDate(), 2) + 'T' + + pad(date.getUTCHours(), 2) + ':' + + pad(date.getUTCMinutes(), 2) + ':' + + pad(date.getUTCSeconds(), 2) + '.' + + pad(date.getUTCMilliseconds(), 3) return ret + '+00:00' } diff --git a/test/unit/utils-tests.js b/test/unit/utils-tests.js index 8898481a..680b9fb5 100644 --- a/test/unit/utils-tests.js +++ b/test/unit/utils-tests.js @@ -139,6 +139,13 @@ test('prepareValue: objects with simple toPostgres prepared properly', function assert.strictEqual(out, 'zomgcustom!') }) +test('prepareValue: buffer array prepared properly', function() { + var buffer1 = Buffer.from('dead', 'hex') + var buffer2 = Buffer.from('beef', 'hex') + var out = utils.prepareValue([buffer1, buffer2]) + assert.strictEqual(out, '{\\\\xdead,\\\\xbeef}') + }) + test('prepareValue: objects with complex toPostgres prepared properly', function () { var buf = Buffer.from('zomgcustom!') var customType = {