diff --git a/app/assets/javascripts/discourse/lib/censored-words.js b/app/assets/javascripts/discourse/lib/censored-words.js index 246bc2a0b..482b19348 100644 --- a/app/assets/javascripts/discourse/lib/censored-words.js +++ b/app/assets/javascripts/discourse/lib/censored-words.js @@ -7,14 +7,14 @@ Discourse.CensoredWords = { 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"); } } if (censorRegexp) { var m = censorRegexp.exec(text); while (m && m[0]) { var replacement = new Array(m[0].length+1).join('■'); - text = text.replace(new RegExp("\\b" + m[0] + "\\b", "ig"), 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 6e8f6e86a..0fbae9431 100644 --- a/test/javascripts/lib/markdown-test.js.es6 +++ b/test/javascripts/lib/markdown-test.js.es6 @@ -569,6 +569,9 @@ test("censoring", function() { cooked("you are a whizzer! I love cheesewhiz. Whiz.", "
you are a ■■■■■■■! I love cheesewhiz. ■■■■.
", "it censors words even if previous partial matches exist."); + cooked("The link still works. [whiz](http://www.whiz.com)", + "The link still works. ■■■■
", + "it won't break links by censoring them."); }); test("code blocks/spans hoisting", function() {