diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-07-10 03:01:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-10 03:01:50 +0200 |
commit | 20fefdb7145b48449e9d6a824a9846dadfd6ac2f (patch) | |
tree | 114ba9b6e63246aa700544a0e211d3ed30d2c572 /app/javascript | |
parent | 1ca4e51eb38de6de81cedf3ddcdaa626f1d1c569 (diff) |
Make whole-word filter regex consistent between Ruby and JS (#7987)
Diffstat (limited to 'app/javascript')
-rw-r--r-- | app/javascript/mastodon/selectors/index.js | 13 |
1 files changed, 12 insertions, 1 deletions
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'); }; |