Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegexError when typing special characters on mentioning. #23

Closed
hirokiky opened this issue Sep 15, 2020 · 0 comments
Closed

RegexError when typing special characters on mentioning. #23

hirokiky opened this issue Sep 15, 2020 · 0 comments

Comments

@hirokiky
Copy link
Contributor

hirokiky commented Sep 15, 2020

Mentionable component will cause error when user type special character like @\ or (@Akyryum) on mentioning.

I think below line may cause error

const reg = new RegExp(this.searchText, 'i')

https://github.com/Akryum/vue-mention/blob/master/packages/vue-mention/src/Mentionable.vue#L73

The this.searchText is user input text, so it can be wrong regexp.
You can check this error on sample application too (Turn on devtools before trying).

https://vue-mention.netlify.app/

Is this rare?

I think it's not rare bug.
The most common case is (@user), like

Hiroki (@hirokiky) reported this bug.

Recommendation

My recommendation is to avoid RegExp.
User inputs won't be regexp basically. So we can simply use .includes and .toLowerCase.

function includesIncase(part, target) {
    return target.toLowerCase().includes(part.toLowerCase())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant