From 5df8d24a4127ffe520ac18481c338bd3953976a7 Mon Sep 17 00:00:00 2001 From: XLor Date: Sun, 16 Apr 2023 00:59:39 +0800 Subject: [PATCH] fix: sql escape --- scripts/sql.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/sql.ts b/scripts/sql.ts index a58f0169..0a4ca9a3 100644 --- a/scripts/sql.ts +++ b/scripts/sql.ts @@ -27,6 +27,7 @@ cli.command('resource', 'Generate resources sql').action(async (option) => { fs.writeFile(`./packages/worker/data/resource-${p}.sql`, chunk.join('\n'), 'utf-8'); } await fs.writeFile('upload.ps1', sc.join('\n'), 'utf-8'); + console.log(`There are ${res.length} resources`); }); cli.command('user', 'Generate user sql').action(async (option) => { @@ -64,7 +65,12 @@ cli.command('team', 'Generate team sql').action(async (option) => { cli.run(process.argv.slice(2)).catch((err) => console.error(err)); function escape(text: string) { - return text.replace(/'/g, `\\'`); + return text + .replace(/%/g, '\\%') + .replace(/\\/g, '\\\\') + .replace(/"/, '\\"') + .replace(/_/g, '\\_') + .replace(/'/g, `\\'`); } async function readResources(root = 'chunk') {