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

autoEscape=false not working

Open hong1997 opened this issue 6 years ago • 3 comments

autoEscape: Escape characters in searchWords which are meaningful in regular expressions. However, when input ‘***x’, the component crashes.

hong1997 avatar Sep 26 '18 01:09 hong1997

Auto escape escapes special characters like "." — but "***x" isn't a valid regexp. Still it shouldn't crash.

If you'd like to contribute a bug fix that would be nice!

bvaughn avatar Sep 26 '18 04:09 bvaughn

I could try and take a look 😄

gndelia avatar Oct 10 '19 22:10 gndelia

The problem seems to be in highlight-words-core package. Essentially, it is trying to create a regex from ***x but that fails. You can try it in the devTools console

new RegExp('***x')

returns

VM127:1 Uncaught SyntaxError: Invalid regular expression: /***x/: Nothing to repeat at new RegExp () at :1:1

I am unsure how to proceed - applying autoEscape=true escapes the special characters and it seems to fix the issue.

Should we log a warning and return an empty array, as "not matching"?

gndelia avatar Oct 10 '19 23:10 gndelia