diff --git a/lib/datatypes.js b/lib/datatypes.js index a95f781..11a34c4 100644 --- a/lib/datatypes.js +++ b/lib/datatypes.js @@ -160,7 +160,9 @@ function decodeBinArray(buf, decodeElem) { // FIXME: one dimension only function encodeTextArray(arr, encodeElem) { - return JSON.stringify(arr.map(encodeElem)).replace(/^\[(.*)]$/, '{$1}'); + return JSON.stringify(arr, function (_, elem) { + return this == arr && elem != null ? encodeElem(elem) : elem; + }).replace(/^\[(.*)]$/, '{$1}'); } // FIXME: one dimension only diff --git a/test/test.js b/test/test.js index 331750d..867bdaa 100644 --- a/test/test.js +++ b/test/test.js @@ -556,7 +556,7 @@ it('param explicit type', async () => { }, }, { type: 'text[]', - value: ['1', '2', '3'], + value: ['1', '2', '3', null], }, { type: 'bytea[]', value: ['x', 'y', 'z'], @@ -567,7 +567,7 @@ it('param explicit type', async () => { 'integer', 1, 'boolean', true, 'jsonb', 'hello', - 'text[]', '{1,2,3}', + 'text[]', '{1,2,3,NULL}', 'bytea[]', '{"\\\\x78","\\\\x79","\\\\x7a"}', ]); });