From 242f5e03016e6aad73890c18914c0d2eaafcc8d4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Jan 2017 10:24:21 +0000 Subject: [PATCH] PR feedback * Doc & properly indent escapeRegExp * Add close bracket to the list of punctuation chars we search after --- src/components/views/dialogs/ChatInviteDialog.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/views/dialogs/ChatInviteDialog.js b/src/components/views/dialogs/ChatInviteDialog.js index 59e95d1538..dfeb2a3978 100644 --- a/src/components/views/dialogs/ChatInviteDialog.js +++ b/src/components/views/dialogs/ChatInviteDialog.js @@ -27,8 +27,13 @@ var Modal = require('../../../Modal'); const TRUNCATE_QUERY_LIST = 40; +/* + * Escapes a string so it can be used in a RegExp + * Basically just replaces: \ ^ $ * + ? . ( ) | { } [ ] + * From http://stackoverflow.com/a/6969486 + */ function escapeRegExp(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); } module.exports = React.createClass({ @@ -326,7 +331,7 @@ module.exports = React.createClass({ // * The start of the string // * Whitespace, or // * A fixed number of punctuation characters - let expr = new RegExp("(?:^|[\\s\\('\",\.-])" + escapeRegExp(query)); + let expr = new RegExp("(?:^|[\\s\\(\)'\",\.-])" + escapeRegExp(query)); if (expr.test(name)) { return true; }