Skip to content

Commit 4a08551

Browse files
authored
Merge pull request #1 from hasura/manas/code-escaping
escape special chars for code templating
2 parents 248c687 + 1012c44 commit 4a08551

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/app/writer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const FunctionName = (title: string): string => {
1717
return camelCase(title);
1818
};
1919

20+
const escapeCodeForTemplateLiteral = (code: string): string => {
21+
return code
22+
.replace(/\\/g, '\\\\') // Escape backslashes
23+
.replace(/`/g, '\\`') // Escape backticks
24+
.replace(/\$/g, '\\$'); // Escape dollar signs
25+
};
26+
2027
export const GenerateTypes = async (
2128
automations: Automation[]
2229
): Promise<string> => {
@@ -78,7 +85,7 @@ const executeProgramEndpoint = utils.mustEnv(
7885
headers: sdk.JSONValue,
7986
input: types.${inputTypeName}
8087
): Promise<utils.ProgramOutput<types.${outputTypeName}>> {
81-
const code = \`${automation.config.data.code}\`;
88+
const code = \`${escapeCodeForTemplateLiteral(automation.config.data.code)}\`;
8289
const body = utils.prepareExecuteProgramBody(
8390
headers,
8491
input,

0 commit comments

Comments
 (0)