Merge pull request #2881 from DeanMarkTaylor/patch-1

FIX: Censored word match fail if earlier partial match
This commit is contained in:
Sam 2014-10-17 15:03:19 +11:00
commit 8b508e704b
2 changed files with 5 additions and 2 deletions

View File

@ -6,7 +6,7 @@ Discourse.Dialect.addPreProcessor(function(text) {
if (!censorRegexp) {
var split = censored.split("|");
if (split && split.length) {
censorRegexp = new RegExp("\\b" + split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|") + "\\b", "ig");
censorRegexp = new RegExp("\\b(?:" + split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|") + ")\\b", "ig");
}
}

View File

@ -481,11 +481,14 @@ test("images", function() {
});
test("censoring", function() {
Discourse.SiteSettings.censored_words = "shucks|whiz";
Discourse.SiteSettings.censored_words = "shucks|whiz|whizzer";
cooked("aw shucks, golly gee whiz.",
"<p>aw &#9632;&#9632;&#9632;&#9632;&#9632;&#9632;, golly gee &#9632;&#9632;&#9632;&#9632;.</p>",
"it censors words in the Site Settings");
cooked("you are a whizzard! I love cheesewhiz. Whiz.",
"<p>you are a whizzard! I love cheesewhiz. &#9632;&#9632;&#9632;&#9632;.</p>",
"it doesn't censor words unless they have boundaries.");
cooked("you are a whizzer! I love cheesewhiz. Whiz.",
"<p>you are a &#9632;&#9632;&#9632;&#9632;&#9632;&#9632;&#9632;! I love cheesewhiz. &#9632;&#9632;&#9632;&#9632;.</p>",
"it censor words even if previous partical matches exist.");
});