mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 03:25:31 -05:00
Stop URLs from being censored (#4288)
URLs that contained a censored word were being altered by censored-words.js and ulimately this broke the links. As an example www.expertsexchange.com would get censored when it would link to a legitimate website. This URL blocking functionality should be handled through other settings.
This commit is contained in:
parent
136b1b504d
commit
e4074f75b1
2 changed files with 5 additions and 2 deletions
|
@ -7,14 +7,14 @@ Discourse.CensoredWords = {
|
||||||
if (!censorRegexp) {
|
if (!censorRegexp) {
|
||||||
var split = censored.split("|");
|
var split = censored.split("|");
|
||||||
if (split && split.length) {
|
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) {
|
if (censorRegexp) {
|
||||||
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(new RegExp("\\b" + m[0] + "\\b", "ig"), replacement);
|
text = text.replace(new RegExp("(\\b" + m[0] + "\\b)(?![^\\(]*\\))", "ig"), replacement);
|
||||||
m = censorRegexp.exec(text);
|
m = censorRegexp.exec(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -569,6 +569,9 @@ test("censoring", function() {
|
||||||
cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
||||||
"<p>you are a ■■■■■■■! I love cheesewhiz. ■■■■.</p>",
|
"<p>you are a ■■■■■■■! I love cheesewhiz. ■■■■.</p>",
|
||||||
"it censors words even if previous partial matches exist.");
|
"it censors words even if previous partial matches exist.");
|
||||||
|
cooked("The link still works. [whiz](http://www.whiz.com)",
|
||||||
|
"<p>The link still works. <a href=\"http://www.whiz.com\">■■■■</a></p>",
|
||||||
|
"it won't break links by censoring them.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("code blocks/spans hoisting", function() {
|
test("code blocks/spans hoisting", function() {
|
||||||
|
|
Loading…
Reference in a new issue