diff --git a/client/views/app/messagePopup.coffee b/client/views/app/messagePopup.coffee index e154bd0c876..511bb0684be 100644 --- a/client/views/app/messagePopup.coffee +++ b/client/views/app/messagePopup.coffee @@ -44,13 +44,13 @@ Template.messagePopup.onCreated -> template.suffix = val(template.data.suffix, ' ') if template.triggerAnywhere is true - template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^| )#{template.trigger}[^\s]*$") + template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^| )#{template.trigger}[^\\s]*$") else - template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^)#{template.trigger}[^\s]*$") + template.matchSelectorRegex = val(template.data.matchSelectorRegex, new RegExp "(?:^)#{template.trigger}[^\\s]*$") - template.selectorRegex = val(template.data.selectorRegex, new RegExp "#{template.trigger}([^\s]*)$") + template.selectorRegex = val(template.data.selectorRegex, new RegExp "#{template.trigger}([^\\s]*)$") - template.replaceRegex = val(template.data.replaceRegex, new RegExp "#{template.trigger}[^\s]*$") + template.replaceRegex = val(template.data.replaceRegex, new RegExp "#{template.trigger}[^\\s]*$") template.getValue = val template.data.getValue, (_id) -> return _id diff --git a/client/views/app/messagePopupConfig.coffee b/client/views/app/messagePopupConfig.coffee index 6d72aad25af..2a72868abb3 100644 --- a/client/views/app/messagePopupConfig.coffee +++ b/client/views/app/messagePopupConfig.coffee @@ -12,7 +12,7 @@ Template.messagePopupConfig.helpers getInput: self.getInput textFilterDelay: 200 getFilter: (collection, filter) -> - exp = new RegExp("#{filter}", 'i') + exp = new RegExp("#{RegExp.escape filter}", 'i') template.userFilter.set filter if template.userSubscription.ready() items = filteredUsers.find({$or: [{username: exp}, {name: exp}]}, {limit: 5}).fetch() @@ -24,7 +24,7 @@ Template.messagePopupConfig.helpers name: t 'Notify_all_in_this_room' compatibility: 'channel group' - exp = new RegExp("(^|\\s)#{filter}", 'i') + exp = new RegExp("(^|\\s)#{RegExp.escape filter}", 'i') if exp.test(all.username) or exp.test(all.compatibility) items.unshift all return items diff --git a/lib/RegExp.coffee b/lib/RegExp.coffee new file mode 100644 index 00000000000..c068aefc58d --- /dev/null +++ b/lib/RegExp.coffee @@ -0,0 +1,2 @@ +RegExp.escape = (s) -> + return s.replace /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' \ No newline at end of file