grafana/public/app/plugins/datasource/grafana-postgresql-datasource/postgresMetaQuery.test.ts
Gábor Farkas 279aa4863b
Postgres: Handle single quotes in table names in the query editor (#80951)
postgres: handle single quotes in table names
2024-01-22 15:36:45 +01:00

15 lines
563 B
TypeScript

import { getSchema } from './postgresMetaQuery';
describe('postgredsMetaQuery.getSchema', () => {
it('should handle table-names with single quote', () => {
// testing multi-line with single-quote, double-quote, backtick
const tableName = `'a''bcd'efg'h' "a""b" ` + '`x``y`z' + `\n a'b''c`;
const escapedName = `''a''''bcd''efg''h'' "a""b" ` + '`x``y`z' + `\n a''b''''c`;
const schemaQuery = getSchema(tableName);
expect(schemaQuery.includes(escapedName)).toBeTruthy();
expect(schemaQuery.includes(tableName)).toBeFalsy();
});
});