Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ABSD
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hub
ABSD
Commits
3046c9f3
Commit
3046c9f3
authored
2 months ago
by
Simon Malesys
Browse files
Options
Downloads
Patches
Plain Diff
Test for escapeString
parent
7821c6ce
No related branches found
No related tags found
No related merge requests found
Pipeline
#149747
passed
2 months ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/server/utils/escapeString.js
+1
-1
1 addition, 1 deletion
src/server/utils/escapeString.js
src/server/utils/escapeString.test.js
+25
-0
25 additions, 0 deletions
src/server/utils/escapeString.test.js
with
26 additions
and
1 deletion
src/server/utils/escapeString.js
+
1
−
1
View file @
3046c9f3
...
...
@@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* Escape all special char
c
aters in a string to make it safe
* Escape all special chara
c
ters in a string to make it safe
* to use in a regex.
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
* @param {string} string - The string containing characters to escape
...
...
This diff is collapsed.
Click to expand it.
src/server/utils/escapeString.test.js
0 → 100644
+
25
−
0
View file @
3046c9f3
// ABSD
// Copyright (C) 2023 Institut Pasteur
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import
{
expect
,
test
}
from
"
vitest
"
import
escapeString
from
"
./escapeString
"
test
(
'
Should escape all dangerous characters in a regex
'
,
()
=>
{
const
dangerousString
=
"
abc.de*fgh+ijk?lmn^op$qr{st}u(vw)xyzABCDE|FG
\
HIJK[LM]NOPQRSTUVWXYZ123456789-_%&#@
"
const
safeString
=
"
abc
\\
.de
\\
*fgh
\\
+ijk
\\
?lmn
\\
^op
\\
$qr
\\
{st
\\
}u
\\
(vw
\\
)xyzABCDE
\\
|FGHIJK
\\
[LM
\\
]NOPQRSTUVWXYZ123456789-_%&#@
"
expect
(
escapeString
(
dangerousString
)).
toBe
(
safeString
)
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment