Re-implement other patch

This commit is contained in:
Brian M. Carlson 2017-07-16 16:39:22 -05:00
parent f9390dab6b
commit ca4ac9983a
2 changed files with 15 additions and 6 deletions

View File

@ -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'
}

View File

@ -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 = {