Skip to content

Commit 8695941

Browse files
committed
refactor(cli): use JSON.stringify for SQL escaping in embed-metrics
- Replaced manual escaping with JSON.stringify for SQL strings - Handles all edge cases (unicode, control characters, etc.) - More robust than manual backslash/backtick/dollar escaping
1 parent a43e629 commit 8695941

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

cli/scripts/embed-metrics.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ function generateTypeScript(metrics: Record<string, MetricDefinition>): string {
128128
// YAML numeric keys may be parsed as numbers or strings depending on context;
129129
// explicitly convert to ensure consistent numeric keys in output
130130
const versionNum = typeof versionKey === "number" ? versionKey : parseInt(versionKey, 10);
131-
// Use template literal for SQL to preserve formatting
132-
const escapedSql = sql.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
133-
lines.push(` ${versionNum}: \`${escapedSql}\`,`);
131+
// Use JSON.stringify for robust escaping of all special characters
132+
lines.push(` ${versionNum}: ${JSON.stringify(sql)},`);
134133
}
135134
lines.push(" },");
136135

0 commit comments

Comments
 (0)