From 7cb7ecaf7ee10c74066ef20cd08d9004de738c15 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Wed, 11 Jul 2018 17:58:25 +0200 Subject: [PATCH] [Glitch] Make whole-word filter regex consistent between Ruby and JS Port front-end part of 20fefdb7145b48449e9d6a824a9846dadfd6ac2f to glitch-soc --- app/javascript/flavours/glitch/selectors/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/selectors/index.js b/app/javascript/flavours/glitch/selectors/index.js index b713a13a6..42881d9ed 100644 --- a/app/javascript/flavours/glitch/selectors/index.js +++ b/app/javascript/flavours/glitch/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'); };