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:
@@ -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, '\\$&');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user