Skip to content

Commit

Permalink
Escape string before regex
Browse files Browse the repository at this point in the history
  • Loading branch information
skakac committed Jan 16, 2023
1 parent ce947b9 commit 3f76ec9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version (v1.0.3)'
description: 'Version (v1.0.4)'
required: true


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solflare-wallet/utl-api",
"version": "1.0.3",
"version": "1.0.4",
"scripts": {
"start:api": "ts-node src/api.ts",
"dev:api": "nodemon src/api.ts",
Expand Down
8 changes: 6 additions & 2 deletions src/api/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export async function searchByContent(
$or: [
{
name: {
$regex: data.query,
$regex: escapeRegex(data.query),
$options: 'i',
},
},
{
symbol: {
$regex: data.query,
$regex: escapeRegex(data.query),
$options: 'i',
},
},
Expand All @@ -98,3 +98,7 @@ export async function searchByContent(
next(error)
}
}

function escapeRegex(string: string) {
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
}

0 comments on commit 3f76ec9

Please sign in to comment.