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) {
var 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;
return Discourse.CensoredWords.censor(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 { propertyEqual } from 'discourse/lib/computed';
import { longDate } from 'discourse/lib/formatter';
import computed from 'ember-addons/ember-computed-decorators';
const Topic = RestModel.extend({
message: null,
errorLoading: false,
fancyTitle: function() {
return Discourse.Emoji.unescape(this.get('fancy_title'));
}.property("fancy_title"),
@computed('fancy_title')
fancyTitle(title) {
title = Discourse.Emoji.unescape(title);
return Discourse.CensoredWords.censor(title);
},
// returns createdAt if there's no bumped date
bumpedAt: function() {

View file

@ -79,6 +79,7 @@ module PrettyText
"vendor/assets/javascripts/better_markdown.js",
"app/assets/javascripts/defer/html-sanitizer-bundle.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/markdown.js",
)