59 lines
2.2 KiB
Java
59 lines
2.2 KiB
Java
package com.discord.utilities.textprocessing;
|
|
|
|
import com.discord.simpleast.core.parser.ParseSpec;
|
|
import com.discord.simpleast.core.parser.Parser;
|
|
import com.discord.simpleast.core.parser.Rule;
|
|
import com.discord.utilities.textprocessing.node.UrlNode;
|
|
import d0.z.d.m;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
/* compiled from: Rules.kt */
|
|
public final class Rules$createMaskedLinkRule$1 extends Rule<T, UrlNode<T>, S> {
|
|
public final /* synthetic */ Rules this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Rules$createMaskedLinkRule$1(Rules rules, Pattern pattern) {
|
|
super(pattern);
|
|
this.this$0 = rules;
|
|
}
|
|
|
|
private final boolean isLikelyPathologicalAttack(CharSequence charSequence) {
|
|
if (charSequence.length() < 30) {
|
|
return false;
|
|
}
|
|
double length = ((double) charSequence.length()) * 0.3d;
|
|
int length2 = charSequence.length();
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < length2; i2++) {
|
|
if (Rules.access$getPATHOLOGICAL_MASKED_LINK_ATTACK_SUSPICIOUS_CHARS$p(Rules.INSTANCE).contains(Character.valueOf(charSequence.charAt(i2)))) {
|
|
i++;
|
|
if (((double) i) > length) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // com.discord.simpleast.core.parser.Rule
|
|
public Matcher match(CharSequence charSequence, String str, S s2) {
|
|
m.checkNotNullParameter(charSequence, "inspectionSource");
|
|
if (isLikelyPathologicalAttack(charSequence)) {
|
|
return null;
|
|
}
|
|
return super.match(charSequence, str, s2);
|
|
}
|
|
|
|
@Override // com.discord.simpleast.core.parser.Rule
|
|
public ParseSpec<T, S> parse(Matcher matcher, Parser<T, ? super UrlNode<T>, S> parser, S s2) {
|
|
m.checkNotNullParameter(matcher, "matcher");
|
|
m.checkNotNullParameter(parser, "parser");
|
|
String group = matcher.group(1);
|
|
m.checkNotNull(group);
|
|
String group2 = matcher.group(2);
|
|
m.checkNotNull(group2);
|
|
UrlNode urlNode = new UrlNode(group2, group);
|
|
m.checkNotNullParameter(urlNode, "node");
|
|
return new ParseSpec<>(urlNode, s2);
|
|
}
|
|
}
|