mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-10-01 07:10:46 -05:00
Improve name highlight matching
- 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
This commit is contained in:
12
js/client.js
12
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');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user