Skip to content

Commit

Permalink
#1 encode null array elements
Browse files Browse the repository at this point in the history
  • Loading branch information
exe-dealer committed Mar 24, 2019
1 parent 09c9538 commit 8375db4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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"}',
]);
});
Expand Down

0 comments on commit 8375db4

Please sign in to comment.