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

fix: escape regex when square brackets are present

Open dorobila opened this issue 2 years ago • 4 comments

Stumbled across react-highlight-words library and noticed that when I add "[" character, it breaks the whole app.

This PR should fix both packages.

image image

dorobila avatar Feb 24 '23 12:02 dorobila

I apologize for my previous commit. Upon further investigation while I was writing a test for it, I discovered that I was using the functions incorrectly andv I've incorrectly assumed that the autoEscape property automatically escapes special characters by default.

I have now reverted my changes and set the autoEscape property to true, as I believe this should be the default behavior.

Let me know what you think.

dorobila avatar Feb 24 '23 14:02 dorobila

Fair enough. Let's just hope no one mistypes "[" instead of "p" without setting autoEscape becasue I certainly did and it broke something similar that I wrote that it highlights some text when searching for something😄.

Feel free to close the PR. Thank you for the chat.

dorobila avatar Feb 24 '23 14:02 dorobila

We could certainly update the demo website :)

bvaughn avatar Feb 24 '23 14:02 bvaughn

Sounds good. I'll create a PR on react-highlight-words demo's website so that it autoescapes by default. Thought about adding a checkbox similar to "Case Sensitive?", but if autoEscape is ticked off, it'll break the app and users are going to have to refresh the page. The example under Usage and the codesandbox are using autoEscape by default, so most of the time users are going to copy/pase the example and build from there.

image

dorobila avatar Feb 24 '23 15:02 dorobila