diff --git a/app/assets/javascripts/discourse/dialects/censored_dialect.js b/app/assets/javascripts/discourse/dialects/censored_dialect.js index 947f70f79..079b84ec9 100644 --- a/app/assets/javascripts/discourse/dialects/censored_dialect.js +++ b/app/assets/javascripts/discourse/dialects/censored_dialect.js @@ -6,7 +6,7 @@ Discourse.Dialect.addPreProcessor(function(text) { if (!censorRegexp) { var split = censored.split("|"); 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); while (m && m[0]) { 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); } diff --git a/test/javascripts/lib/markdown-test.js.es6 b/test/javascripts/lib/markdown-test.js.es6 index 2420f51d1..08eb2f87d 100644 --- a/test/javascripts/lib/markdown-test.js.es6 +++ b/test/javascripts/lib/markdown-test.js.es6 @@ -485,4 +485,7 @@ test("censoring", function() { cooked("aw shucks, golly gee whiz.", "
aw ■■■■■■, golly gee ■■■■.
", "it censors words in the Site Settings"); + cooked("you are a whizzard! I love cheesewhiz. Whiz.", + "you are a whizzard! I love cheesewhiz. ■■■■.
", + "it doesn't censor words unless they have boundaries."); });