Skip to content

Commit

Permalink
Fixing bug for filenames not escaped in compiled graph taget and cann…
Browse files Browse the repository at this point in the history
…onical target (#1551)
  • Loading branch information
maverickjoy authored Oct 18, 2023
1 parent 2ce51b4 commit 4ee558e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}\`;
Expand All @@ -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");
Expand All @@ -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}\`;
Expand Down Expand Up @@ -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 || "{}"}
},
Expand Down
5 changes: 5 additions & 0 deletions core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4ee558e

Please sign in to comment.