Skip to content
Snippets Groups Projects
Commit 3046c9f3 authored by Simon Malesys's avatar Simon Malesys
Browse files

Test for escapeString

parent 7821c6ce
No related branches found
No related tags found
No related merge requests found
Pipeline #149747 passed
......@@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* Escape all special charcaters in a string to make it safe
* Escape all special characters 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
......
// 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)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment