Skip to content

Commit bf10682

Browse files
committed
fixing null|undefined for _TN function
1 parent 19776db commit bf10682

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/helpers/table-name.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ npm.utils.addInspection(TableName, function () {
156156
*/
157157
function _TN(a, ...args) {
158158
if (Array.isArray(a) && a.raw) {
159-
a = a.map((b, i) => b + (i < args.length ? args[i] : '')).join('');
159+
a = a.map((b, i) => b + (i < args.length ? args[i] ?? '' : '')).join('');
160160
} // else 'a' is a string
161161
const [schema, table] = a.split('.');
162-
if(table === undefined) {
162+
if (table === undefined) {
163163
return {table: schema};
164164
}
165165
return schema ? {schema, table} : {table};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-promise",
3-
"version": "11.7.6",
3+
"version": "11.7.7",
44
"description": "PostgreSQL interface for Node.js",
55
"main": "lib/index.js",
66
"typings": "typescript/pg-promise.d.ts",

test/help.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -982,5 +982,17 @@ describe('_TN', () => {
982982
expect(helpers._TN`${schema}.${table}`).toEqual({schema: 'ss', table: 'tt'});
983983
expect(helpers._TN`${schema}.${table}.`).toEqual({schema: 'ss', table: 'tt'});
984984
});
985+
it('must support null parameters', () => {
986+
const schema = null, table = null;
987+
expect(helpers._TN`${schema}.${table}`).toEqual({table: ''});
988+
expect(helpers._TN`ss.${table}`).toEqual({schema: 'ss', table: ''});
989+
expect(helpers._TN`${schema}.tt`).toEqual({table: 'tt'});
990+
});
991+
it('must support undefined parameters', () => {
992+
const schema = undefined, table = undefined;
993+
expect(helpers._TN`${schema}.${table}`).toEqual({table: ''});
994+
expect(helpers._TN`ss.${table}`).toEqual({schema: 'ss', table: ''});
995+
expect(helpers._TN`${schema}.tt`).toEqual({table: 'tt'});
996+
});
985997
});
986998
});

0 commit comments

Comments
 (0)