Escape channel metrics literals and bypass website transfer lookup for admins

This commit is contained in:
Mike Cao committed 2026-07-24 18:49:02 -07:00
1 parent 8148d775b0
commit dab6180056
6 files changed
+81 -31

No files matched your search

+9 -2
View File
@@ -174,9 +174,16 @@ async function clickhouseQuery(
}
function toClickHouseStringArray(arr: string[]): string {
return arr.map(p => `'${p.replace(/'/g, "\\'")}'`).join(', ');
// Escape backslashes first, then single quotes, for ClickHouse string literals.
return arr.map(p => `'${p.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`).join(', ');
}
function escapePostgresLikeValue(val: string) {
// Escape LIKE wildcards/backslashes so the value is matched literally, then
// escape single quotes for the surrounding SQL string literal.
return val.replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_').replace(/'/g, "''");
}
function toPostgresLikeClause(column: string, arr: string[]) {
return arr.map(val => `${column} ilike '%${val.replace(/'/g, "''")}%'`).join(' OR\n ');
return arr.map(val => `${column} ilike '%${escapePostgresLikeValue(val)}%'`).join(' OR\n ');
}