diff --git a/app/javascript/dashboard/routes/dashboard/conversation/search/SearchMessageItem.vue b/app/javascript/dashboard/routes/dashboard/conversation/search/SearchMessageItem.vue index ee66d2646..172c8f250 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/search/SearchMessageItem.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/search/SearchMessageItem.vue @@ -64,11 +64,16 @@ export default { methods: { prepareContent(content = '') { const plainTextContent = this.getPlainText(content); + const escapedSearchTerm = this.escapeRegExp(this.searchTerm); return plainTextContent.replace( - new RegExp(`(${this.searchTerm})`, 'ig'), + new RegExp(`(${escapedSearchTerm})`, 'ig'), '$1' ); }, + // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping + escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + }, }, };