Merge pull request #3692 from tgxworld/fix_title_not_censored

FIX: Censored words filter not applied to title.
This commit is contained in:
Régis Hanol 2015-08-25 16:54:09 +02:00
commit a8edc98276
4 changed files with 33 additions and 25 deletions

View File

@ -1,24 +1,3 @@
var censorRegexp;
Discourse.Dialect.addPreProcessor(function(text) { Discourse.Dialect.addPreProcessor(function(text) {
var censored = Discourse.SiteSettings.censored_words; return Discourse.CensoredWords.censor(text);
if (censored && censored.length) {
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");
}
}
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);
m = censorRegexp.exec(text);
}
}
}
return text;
}); });

View File

@ -0,0 +1,25 @@
Discourse.CensoredWords = {
censor: function(text) {
var censorRegexp,
censored = Discourse.SiteSettings.censored_words;
if (censored && censored.length) {
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");
}
}
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);
m = censorRegexp.exec(text);
}
}
}
return text;
}
}

View File

@ -2,14 +2,17 @@ import { flushMap } from 'discourse/models/store';
import RestModel from 'discourse/models/rest'; import RestModel from 'discourse/models/rest';
import { propertyEqual } from 'discourse/lib/computed'; import { propertyEqual } from 'discourse/lib/computed';
import { longDate } from 'discourse/lib/formatter'; import { longDate } from 'discourse/lib/formatter';
import computed from 'ember-addons/ember-computed-decorators';
const Topic = RestModel.extend({ const Topic = RestModel.extend({
message: null, message: null,
errorLoading: false, errorLoading: false,
fancyTitle: function() { @computed('fancy_title')
return Discourse.Emoji.unescape(this.get('fancy_title')); fancyTitle(title) {
}.property("fancy_title"), title = Discourse.Emoji.unescape(title);
return Discourse.CensoredWords.censor(title);
},
// returns createdAt if there's no bumped date // returns createdAt if there's no bumped date
bumpedAt: function() { bumpedAt: function() {

View File

@ -79,6 +79,7 @@ module PrettyText
"vendor/assets/javascripts/better_markdown.js", "vendor/assets/javascripts/better_markdown.js",
"app/assets/javascripts/defer/html-sanitizer-bundle.js", "app/assets/javascripts/defer/html-sanitizer-bundle.js",
"app/assets/javascripts/discourse/dialects/dialect.js", "app/assets/javascripts/discourse/dialects/dialect.js",
"app/assets/javascripts/discourse/lib/censored-words.js",
"app/assets/javascripts/discourse/lib/utilities.js", "app/assets/javascripts/discourse/lib/utilities.js",
"app/assets/javascripts/discourse/lib/markdown.js", "app/assets/javascripts/discourse/lib/markdown.js",
) )