highlight-words-core
highlight-words-core copied to clipboard
fix: escape regex when square brackets are present
Stumbled across react-highlight-words library and noticed that when I add "[" character, it breaks the whole app.
This PR should fix both packages.
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.
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.
We could certainly update the demo website :)
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.