fix(MySQL Node): Only escape table names when needed (#8246)

This commit is contained in:
Elias Meire
2024-01-10 14:41:00 +01:00
committed by GitHub
parent dce28f9cb9
commit 3b01eb60c9
8 changed files with 81 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ import {
addWhereClauses,
addSortRules,
replaceEmptyStringsByNulls,
escapeSqlIdentifier,
} from '../../v2/helpers/utils';
const mySqlMockNode: INode = {
@@ -148,3 +149,29 @@ describe('Test MySql V2, replaceEmptyStringsByNulls', () => {
expect(replacedData).toEqual([{ json: { id: 1, name: '' } }]);
});
});
describe('Test MySql V2, escapeSqlIdentifier', () => {
it('should escape fully qualified identifier', () => {
const input = 'db_name.tbl_name.col_name';
const escapedIdentifier = escapeSqlIdentifier(input);
expect(escapedIdentifier).toEqual('`db_name`.`tbl_name`.`col_name`');
});
it('should escape table name only', () => {
const input = 'tbl_name';
const escapedIdentifier = escapeSqlIdentifier(input);
expect(escapedIdentifier).toEqual('`tbl_name`');
});
it('should escape fully qualified identifier with backticks', () => {
const input = '`db_name`.`tbl_name`.`col_name`';
const escapedIdentifier = escapeSqlIdentifier(input);
expect(escapedIdentifier).toEqual('`db_name`.`tbl_name`.`col_name`');
});
it('should escape identifier with dots', () => {
const input = '`db_name`.`some.dotted.tbl_name`';
const escapedIdentifier = escapeSqlIdentifier(input);
expect(escapedIdentifier).toEqual('`db_name`.`some.dotted.tbl_name`');
});
});