Skip to content

Commit

Permalink
fix: RegexError when typing special characters on mentioning (#24), c…
Browse files Browse the repository at this point in the history
…loses #23

* Added a test to find out #23 issue.

* Fixed RegexError bug on filteredItems computed (see #23).

* refactor: less toLowerCase calls

Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
  • Loading branch information
hirokiky and Akryum committed Dec 28, 2020
1 parent 17f7e52 commit 49eeb94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
7 changes: 7 additions & 0 deletions packages/test-e2e/tests/e2e/specs/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ describe('with default props', () => {
cy.get('.preview').should('contain', '@akryumabc')
})

it('no error with special characters', () => {
cy.visit('/defaults')
cy.get('.input').type('@\\')
cy.get('.popover').should('be.visible')
.should('contain', 'No result')
})

it('show suggestion when previous input is space', () => {
cy.visit('/defaults')
cy.get('.input').type(' @zzz')
Expand Down
23 changes: 13 additions & 10 deletions packages/vue-mention/src/Mentionable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,22 @@ export default {
return this.items
}
const reg = new RegExp(this.searchText, 'i')
const searchText = this.searchText.toLowerCase()
return this.items.filter(item => {
/** @type {string} */
let text
if (item.searchText) {
return reg.test(item.searchText)
}
if (item.label) {
return reg.test(item.label)
}
let text = ''
for (const key in item) {
text += item[key]
text = item.searchText
} else if (item.label) {
text = item.label
} else {
text = ''
for (const key in item) {
text += item[key]
}
}
return reg.test(text)
return text.toLowerCase().includes(searchText)
})
},
Expand Down

0 comments on commit 49eeb94

Please sign in to comment.