mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-25 01:24:02 -05:00
[Glitch] Make whole-word filter regex consistent between Ruby and JS
Port front-end part of 20fefdb714
to glitch-soc
This commit is contained in:
parent
debc6544d9
commit
7cb7ecaf7e
@ -47,7 +47,18 @@ export const regexFromFilters = filters => {
|
|||||||
|
|
||||||
return new RegExp(filters.map(filter => {
|
return new RegExp(filters.map(filter => {
|
||||||
let expr = escapeRegExp(filter.get('phrase'));
|
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');
|
}).join('|'), 'i');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user