about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/selectors
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-07-11 17:58:25 +0200
committerThibG <thib@sitedethib.com>2018-07-11 22:06:34 +0200
commit7cb7ecaf7ee10c74066ef20cd08d9004de738c15 (patch)
treed8b56f30a66b146e48a838e8c7745b02296c1c97 /app/javascript/flavours/glitch/selectors
parentdebc6544d9e2881b175d4e5de09c7b40a1f7e503 (diff)
[Glitch] Make whole-word filter regex consistent between Ruby and JS
Port front-end part of 20fefdb7145b48449e9d6a824a9846dadfd6ac2f to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/selectors')
-rw-r--r--app/javascript/flavours/glitch/selectors/index.js13
1 files changed, 12 insertions, 1 deletions
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');
 };