[Glitch] Make whole-word filter regex consistent between Ruby and JS

Port front-end part of a94f6c800d to glitch-soc
lolsob-rspec
Thibaut Girka 2018-07-11 17:58:25 +02:00 committed by ThibG
parent 78fcb67c12
commit 052f5324fc
1 changed files with 12 additions and 1 deletions

View File

@ -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');
};