From 0a5acba77ecfd94ec4e7d4c40d0f36cc93ee0e45 Mon Sep 17 00:00:00 2001 From: Dean Taylor Date: Fri, 17 Oct 2014 02:43:28 +0100 Subject: [PATCH 1/2] FIX: Censored word match fail if earlier partial match --- app/assets/javascripts/discourse/dialects/censored_dialect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/dialects/censored_dialect.js b/app/assets/javascripts/discourse/dialects/censored_dialect.js index 079b84ec9c4..1cb38a9115a 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("\\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"); } } From b023e81078ec967efa531af796ff568decc1a9e1 Mon Sep 17 00:00:00 2001 From: Dean Taylor Date: Fri, 17 Oct 2014 03:10:30 +0100 Subject: [PATCH 2/2] FIX: Censored word match fail if earlier partial match Previously a list containing `one|two|three|four|twoagain` would fail to censor the word `twoagain` in the text `test1 twoagain test2`. --- test/javascripts/lib/markdown-test.js.es6 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/javascripts/lib/markdown-test.js.es6 b/test/javascripts/lib/markdown-test.js.es6 index 08eb2f87d49..2fa4f7066c5 100644 --- a/test/javascripts/lib/markdown-test.js.es6 +++ b/test/javascripts/lib/markdown-test.js.es6 @@ -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.", "

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."); + cooked("you are a whizzer! I love cheesewhiz. Whiz.", + "

you are a ■■■■■■■! I love cheesewhiz. ■■■■.

", + "it censor words even if previous partical matches exist."); });