Invalid Regex when trigger contains multiple characters like ((
louisbourque opened this issue · 3 comments
Version: 4.6.2
When specifying a trigger like '((', the second '(' character is not escaped in the generated Regex, causing it to be invalid:
Uncaught SyntaxError: Invalid regular expression: /([|=|(()((?:(?!\1)[^\s])*$)/: Unterminated group
The Regex should be /([|=|(()((?:(?!\1)[^\s])*$)/
Example: https://codesandbox.io/s/silent-sound-e7uik
The same issue happens when the second character of the trigger is '['
We need to properly escape every of trigger chars. Should be quite straightforward, since we already escape the first one. Do you wanna go for a PR?
@jukben I'd be happy to give it a try. I had a look at it some more and it looks like the first character is always escaped. This means that if a trigger character of 's' is used, the trigger won't work. It's interpreted by the Regexp as a space character. Typing a space then another letter causes a TypeError because the trigger is not found:
TypeError
trigger[currentTrigger] is undefined
I'll work on a PR, thanks!
Released in https://github.com/webscopeio/react-textarea-autocomplete/releases/tag/v4.6.3 Thanks for contribution!