From 4ee558e9165ee667a4d23fe1418403939513a26f Mon Sep 17 00:00:00 2001 From: VIKRAM SINGH Date: Wed, 18 Oct 2023 14:26:15 +0100 Subject: [PATCH] Fixing bug for filenames not escaped in compiled graph taget and cannonical target (#1551) --- core/compilers.ts | 8 ++++---- core/utils.ts | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/compilers.ts b/core/compilers.ts index d076bd4a0..d1d70ba70 100644 --- a/core/compilers.ts +++ b/core/compilers.ts @@ -32,7 +32,7 @@ function compileTableSql(code: string, path: string) { ); return ` - publish("${utils.baseFilename(path)}").query(ctx => { + publish("${utils.getEscapedFileName(path)}").query(ctx => { ${functionsBindings.join("\n")} ${js} return \`${sql}\`; @@ -46,7 +46,7 @@ function compileOperationSql(code: string, path: string) { ); return ` - operate("${utils.baseFilename(path)}").queries(ctx => { + operate("${utils.getEscapedFileName(path)}").queries(ctx => { ${functionsBindings.join("\n")} ${js} return \`${sql}\`.split("\\n---\\n"); @@ -60,7 +60,7 @@ function compileAssertionSql(code: string, path: string) { ); return ` - assert("${utils.baseFilename(path)}").query(ctx => { + assert("${utils.getEscapedFileName(path)}").query(ctx => { ${functionsBindings.join("\n")} ${js} return \`${sql}\`; @@ -128,7 +128,7 @@ function compileSqlx(rootNode: SyntaxTreeNode, path: string) { return `dataform.sqlxAction({ sqlxConfig: { - name: "${utils.baseFilename(path)}", + name: "${utils.getEscapedFileName(path)}", type: "operations", ...${config || "{}"} }, diff --git a/core/utils.ts b/core/utils.ts index 92134ae17..e513cc009 100644 --- a/core/utils.ts +++ b/core/utils.ts @@ -33,6 +33,10 @@ export function baseFilename(fullPath: string) { .split(".")[0]; } +export function getEscapedFileName(path: string) { + return baseFilename(path).replace(/\\/g, '\\\\') +} + export function matchPatterns(patterns: string[], values: string[]) { const fullyQualifiedActions: string[] = []; patterns.forEach(pattern => { @@ -270,6 +274,7 @@ export function tableTypeEnumToString(enumType: dataform.TableType) { return dataform.TableType[enumType].toLowerCase(); } + export function setOrValidateTableEnumType(table: dataform.ITable) { let enumTypeFromStr: dataform.TableType | null = null; if (table.type !== "" && table.type !== undefined) {