mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-25 16:04:22 -05:00
FIX: Check for word boundaries with censored words.
This commit is contained in:
parent
80183f04f5
commit
3b38667274
2 changed files with 5 additions and 2 deletions
|
@ -6,7 +6,7 @@ Discourse.Dialect.addPreProcessor(function(text) {
|
||||||
if (!censorRegexp) {
|
if (!censorRegexp) {
|
||||||
var split = censored.split("|");
|
var split = censored.split("|");
|
||||||
if (split && split.length) {
|
if (split && split.length) {
|
||||||
censorRegexp = new RegExp(split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|"), "ig");
|
censorRegexp = new RegExp("\\b" + split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|") + "\\b", "ig");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ Discourse.Dialect.addPreProcessor(function(text) {
|
||||||
var m = censorRegexp.exec(text);
|
var m = censorRegexp.exec(text);
|
||||||
while (m && m[0]) {
|
while (m && m[0]) {
|
||||||
var replacement = new Array(m[0].length+1).join('■');
|
var replacement = new Array(m[0].length+1).join('■');
|
||||||
text = text.replace(m[0], replacement);
|
text = text.replace(new RegExp("\\b" + m[0] + "\\b", "ig"), replacement);
|
||||||
m = censorRegexp.exec(text);
|
m = censorRegexp.exec(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -485,4 +485,7 @@ test("censoring", function() {
|
||||||
cooked("aw shucks, golly gee whiz.",
|
cooked("aw shucks, golly gee whiz.",
|
||||||
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
||||||
"it censors words in the Site Settings");
|
"it censors words in the Site Settings");
|
||||||
|
cooked("you are a whizzard! I love cheesewhiz. Whiz.",
|
||||||
|
"<p>you are a whizzard! I love cheesewhiz. ■■■■.</p>",
|
||||||
|
"it doesn't censor words unless they have boundaries.");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue