mirror of
https://github.com/discourse/discourse.git
synced 2024-12-11 15:33:52 +08:00
39e0442de9
- Client-side censoring fixed for non-chrome browsers. (Regular expression rewritten to avoid lookback) - Regex generation is now done on the server, to reduce repeated logic, and make it easier to extend in plugins - Censor tests are moved to ruby, to ensure everything works end-to-end - If "watched words regular expressions" is enabled, warn the admin when the generated regex is invalid
27 lines
722 B
JavaScript
27 lines
722 B
JavaScript
export function censorFn(regexpString, replacementLetter) {
|
|
if (regexpString) {
|
|
let censorRegexp = new RegExp(regexpString, "ig");
|
|
replacementLetter = replacementLetter || "■";
|
|
|
|
return function(text) {
|
|
text = text.replace(censorRegexp, (fullMatch, ...groupMatches) => {
|
|
const stringMatch = groupMatches.find(g => typeof g === "string");
|
|
return fullMatch.replace(
|
|
stringMatch,
|
|
new Array(stringMatch.length + 1).join(replacementLetter)
|
|
);
|
|
});
|
|
|
|
return text;
|
|
};
|
|
}
|
|
|
|
return function(t) {
|
|
return t;
|
|
};
|
|
}
|
|
|
|
export function censor(text, censoredRegexp, replacementLetter) {
|
|
return censorFn(censoredRegexp, replacementLetter)(text);
|
|
}
|