From 20fefdb7145b48449e9d6a824a9846dadfd6ac2f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 10 Jul 2018 03:01:50 +0200 Subject: Make whole-word filter regex consistent between Ruby and JS (#7987) --- app/javascript/mastodon/selectors/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'app/javascript') diff --git a/app/javascript/mastodon/selectors/index.js b/app/javascript/mastodon/selectors/index.js index d0212c379..106198f74 100644 --- a/app/javascript/mastodon/selectors/index.js +++ b/app/javascript/mastodon/selectors/index.js @@ -47,7 +47,18 @@ export const regexFromFilters = filters => { return new RegExp(filters.map(filter => { let expr = escapeRegExp(filter.get('phrase')); - return filter.get('whole_word') ? `\\b${expr}\\b` : expr; + + if (filter.get('whole_word')) { + if (/^[\w]/.test(expr)) { + expr = `\\b${expr}`; + } + + if (/[\w]$/.test(expr)) { + expr = `${expr}\\b`; + } + } + + return expr; }).join('|'), 'i'); }; -- cgit