diff --git a/lib/helpers/table-name.js b/lib/helpers/table-name.js index 909ebd23..b024892f 100644 --- a/lib/helpers/table-name.js +++ b/lib/helpers/table-name.js @@ -156,10 +156,10 @@ npm.utils.addInspection(TableName, function () { */ function _TN(a, ...args) { if (Array.isArray(a) && a.raw) { - a = a.map((b, i) => b + (i < args.length ? args[i] : '')).join(''); + a = a.map((b, i) => b + (i < args.length ? args[i] ?? '' : '')).join(''); } // else 'a' is a string const [schema, table] = a.split('.'); - if(table === undefined) { + if (table === undefined) { return {table: schema}; } return schema ? {schema, table} : {table}; diff --git a/package.json b/package.json index f824d6f5..3e017d00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg-promise", - "version": "11.7.6", + "version": "11.7.7", "description": "PostgreSQL interface for Node.js", "main": "lib/index.js", "typings": "typescript/pg-promise.d.ts", diff --git a/test/help.spec.js b/test/help.spec.js index b1c74158..30bb27f5 100644 --- a/test/help.spec.js +++ b/test/help.spec.js @@ -982,5 +982,17 @@ describe('_TN', () => { expect(helpers._TN`${schema}.${table}`).toEqual({schema: 'ss', table: 'tt'}); expect(helpers._TN`${schema}.${table}.`).toEqual({schema: 'ss', table: 'tt'}); }); + it('must support null parameters', () => { + const schema = null, table = null; + expect(helpers._TN`${schema}.${table}`).toEqual({table: ''}); + expect(helpers._TN`ss.${table}`).toEqual({schema: 'ss', table: ''}); + expect(helpers._TN`${schema}.tt`).toEqual({table: 'tt'}); + }); + it('must support undefined parameters', () => { + const schema = undefined, table = undefined; + expect(helpers._TN`${schema}.${table}`).toEqual({table: ''}); + expect(helpers._TN`ss.${table}`).toEqual({schema: 'ss', table: ''}); + expect(helpers._TN`${schema}.tt`).toEqual({table: 'tt'}); + }); }); });