improve domain check logic
This commit is contained in:
@@ -61,7 +61,11 @@ public class MastodonAPIController{
|
|||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if (line.isBlank() || line.startsWith("#")) continue;
|
if (line.isBlank() || line.startsWith("#")) continue;
|
||||||
badDomains.add(line.toLowerCase().trim());
|
String[] parts = line.replaceAll("\"", "").split("[\s,;]");
|
||||||
|
if (parts.length == 0) continue;
|
||||||
|
String domain = parts[0].toLowerCase().trim();
|
||||||
|
if (domain.isBlank()) continue;
|
||||||
|
badDomains.add(domain);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -73,8 +77,8 @@ public class MastodonAPIController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> void submitRequest(final MastodonAPIRequest<T> req){
|
public <T> void submitRequest(final MastodonAPIRequest<T> req){
|
||||||
final String host = req.getURL().getHost().toLowerCase();
|
final String host = req.getURL().getHost();
|
||||||
final boolean isBad = badDomains.stream().anyMatch(host::endsWith);
|
final boolean isBad = host == null || badDomains.stream().anyMatch(h -> h.equalsIgnoreCase(host) || host.toLowerCase().endsWith("." + h));
|
||||||
thread.postRunnable(()->{
|
thread.postRunnable(()->{
|
||||||
try{
|
try{
|
||||||
if (isBad) throw new IllegalArgumentException();
|
if (isBad) throw new IllegalArgumentException();
|
||||||
|
|||||||
Reference in New Issue
Block a user