Skip to content

Commit ca4ac99

Browse files
committed
Re-implement other patch
1 parent f9390da commit ca4ac99

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/utils.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function arrayString (val) {
3232
result = result + 'NULL'
3333
} else if (Array.isArray(val[i])) {
3434
result = result + arrayString(val[i])
35+
} else if (val[i] instanceof Buffer) {
36+
result += '\\\\x' + val[i].toString('hex')
3537
} else {
3638
result += escapeElement(prepareValue(val[i]))
3739
}
@@ -106,12 +108,12 @@ function dateToString (date) {
106108

107109
function dateToStringUTC (date) {
108110
var ret = pad(date.getUTCFullYear(), 4) + '-' +
109-
pad(date.getUTCMonth() + 1, 2) + '-' +
110-
pad(date.getUTCDate(), 2) + 'T' +
111-
pad(date.getUTCHours(), 2) + ':' +
112-
pad(date.getUTCMinutes(), 2) + ':' +
113-
pad(date.getUTCSeconds(), 2) + '.' +
114-
pad(date.getUTCMilliseconds(), 3)
111+
pad(date.getUTCMonth() + 1, 2) + '-' +
112+
pad(date.getUTCDate(), 2) + 'T' +
113+
pad(date.getUTCHours(), 2) + ':' +
114+
pad(date.getUTCMinutes(), 2) + ':' +
115+
pad(date.getUTCSeconds(), 2) + '.' +
116+
pad(date.getUTCMilliseconds(), 3)
115117

116118
return ret + '+00:00'
117119
}

test/unit/utils-tests.js

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ test('prepareValue: objects with simple toPostgres prepared properly', function
139139
assert.strictEqual(out, 'zomgcustom!')
140140
})
141141

142+
test('prepareValue: buffer array prepared properly', function() {
143+
var buffer1 = Buffer.from('dead', 'hex')
144+
var buffer2 = Buffer.from('beef', 'hex')
145+
var out = utils.prepareValue([buffer1, buffer2])
146+
assert.strictEqual(out, '{\\\\xdead,\\\\xbeef}')
147+
})
148+
142149
test('prepareValue: objects with complex toPostgres prepared properly', function () {
143150
var buf = Buffer.from('zomgcustom!')
144151
var customType = {

0 commit comments

Comments
 (0)