test(escapeRegExp): Just an extra test to make sure non-regexy strings don't get escaped

Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
Harry Hogg
2021-10-18 11:00:01 +01:00
parent deaec1ee3f
commit 4b92638259
2 changed files with 5 additions and 1 deletions
@@ -16,6 +16,10 @@
import { escapeRegExp } from './escapeRegExp';
describe('escapeRegExp', () => {
test('does not escape non-regex characters', () => {
expect(escapeRegExp('Backstage Backstage')).toBe('Backstage Backstage');
});
test('all the characters', () => {
expect(escapeRegExp('^$\\.*+?()[]{}|')).toBe(
'\\^\\$\\\\\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|',
@@ -20,5 +20,5 @@
* Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
*/
export const escapeRegExp = (text: string) => {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return text.replace(/[.*+?^${}(\)|[\]\\]/g, '\\$&');
};