Merge "Clean up disrespectful terms"

This commit is contained in:
Gal Paikin
2020-09-23 13:50:14 +00:00
committed by Gerrit Code Review
4 changed files with 57 additions and 25 deletions

View File

@@ -35,7 +35,7 @@ public class HtmlParser {
"gmail_quote" // Used for quoting original content
);
private static final ImmutableSet<String> WHITELISTED_HTML_TAGS =
private static final ImmutableSet<String> ALLOWED_HTML_TAGS =
ImmutableSet.of(
"div", // Most user-typed comments are contained in a <div> tag
"a", // We allow links to be contained in a comment
@@ -120,8 +120,8 @@ public class HtmlParser {
// There is no user-input in quoted text
continue;
}
if (!WHITELISTED_HTML_TAGS.contains(elementName)) {
// We only accept a set of whitelisted tags that can contain user input
if (!ALLOWED_HTML_TAGS.contains(elementName)) {
// We only accept a set of allowed tags that can contain user input
continue;
}
if (elementName.equals("a") && e.attr("href").startsWith("mailto:")) {

View File

@@ -31,8 +31,8 @@ public class ListMailFilter implements MailFilter {
public enum ListFilterMode {
OFF,
WHITELIST,
BLACKLIST
ALLOW,
BLOCK
}
private final ListFilterMode mode;
@@ -40,12 +40,37 @@ public class ListMailFilter implements MailFilter {
@Inject
ListMailFilter(@GerritServerConfig Config cfg) {
this.mode = cfg.getEnum("receiveemail", "filter", "mode", ListFilterMode.OFF);
mode = getListFilterMode(cfg);
String[] addresses = cfg.getStringList("receiveemail", "filter", "patterns");
String concat = Arrays.asList(addresses).stream().collect(joining("|"));
this.mailPattern = Pattern.compile(concat);
}
private static final String LEGACY_ALLOW = "WHITELIST";
private static final String LEGACY_BLOCK = "BLACKLIST";
/** Legacy names are supported, but should be removed in the future. */
private ListFilterMode getListFilterMode(Config cfg) {
ListFilterMode mode;
String modeString = cfg.getString("receiveemail", "filter", "mode");
if (modeString == null) {
modeString = "";
}
switch (modeString) {
case LEGACY_ALLOW:
case "ALLOW":
mode = ListFilterMode.ALLOW;
break;
case LEGACY_BLOCK:
case "BLOCK":
mode = ListFilterMode.BLOCK;
break;
default:
mode = ListFilterMode.OFF;
}
return mode;
}
@Override
public boolean shouldProcessMessage(MailMessage message) {
if (mode == ListFilterMode.OFF) {
@@ -53,8 +78,7 @@ public class ListMailFilter implements MailFilter {
}
boolean match = mailPattern.matcher(message.from().email()).find();
if ((mode == ListFilterMode.WHITELIST && !match)
|| (mode == ListFilterMode.BLACKLIST && match)) {
if ((mode == ListFilterMode.ALLOW && !match) || (mode == ListFilterMode.BLOCK && match)) {
logger.atInfo().log("Mail message from %s rejected by list filter", message.from());
return false;
}