Skip to content

Commit

Permalink
fix: sql escape
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 15, 2023
1 parent 65f6964 commit 5df8d24
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 5df8d24

Please sign in to comment.