From ddd4e6745013572c50368c8e0a31efdafbd27ae3 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Mon, 30 Nov 2015 20:26:41 -0500 Subject: [PATCH] Improve name highlight matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Special characters at the end of a name are ignored - Non-ASCII characters in the middle of a name can be replaced with any other non-alphanumeric character So, for instance, with a user named 'te•st••': 'test', 'te st', and 'te-st' would all highlight them --- js/client.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/client.js b/js/client.js index 7549e6e2e..9f7ede933 100644 --- a/js/client.js +++ b/js/client.js @@ -162,7 +162,17 @@ if (!self.get('named')) { self.nameRegExp = null; } else { - self.nameRegExp = new RegExp('(?:\\b|(?!\\w))' + Tools.escapeRegExp(self.get('name')) + '(?:\\b|\\B(?!\\w))', 'i'); + var escaped = self.get('name').replace(/[^A-Za-z0-9]+$/, ''); + // we'll use `,` as a sentinel character to mean "any non-alphanumeric char" + // unicode characters can be replaced with any non-alphanumeric char + for (var i = escaped.length - 1; i > 0; i--) { + if (/[^\ -\~]/.test(escaped[i])) { + escaped = escaped.slice(0, i) + ',' + escaped.slice(i + 1); + } + } + escaped = escaped.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + escaped = escaped.replace(/,/g, "[^A-Za-z0-9]?"); + self.nameRegExp = new RegExp('(?:\\b|(?!\\w))' + escaped + '(?:\\b|\\B(?!\\w))', 'i'); } });