react-highlight-words icon indicating copy to clipboard operation
react-highlight-words copied to clipboard

autoEscape not working when one of the searchWords is regex

Open mkurek opened this issue 6 years ago • 2 comments

When autoEscape is set to true and (at least) one of the elements in searchWords array is regex, the following exception is raised:

TypeError
str.replace is not a function

Example: https://codesandbox.io/s/20p3zk380n

mkurek avatar Sep 24 '18 08:09 mkurek

The autoEscape parameter is meant to escape sensitive characters before converting a string to a regex. It's not meant to work with regexes.

I guess this is a bug, but I don't plan on fixing it. I'd be happy to review a PR though.

bvaughn avatar Sep 24 '18 14:09 bvaughn

Suggestion: Check instanceof RegExp for each searchWords value in the autoescape function and don't escape if it is RegExp.

warmbowski avatar May 15 '23 20:05 warmbowski