From 6bc23ed43bd7f79e72755a6f1625e3e3e2367256 Mon Sep 17 00:00:00 2001 From: FongMi Date: Thu, 18 Dec 2025 17:01:57 +0800 Subject: [PATCH] Fix bug --- .../src/main/java/com/github/catvod/net/OkDns.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/catvod/src/main/java/com/github/catvod/net/OkDns.java b/catvod/src/main/java/com/github/catvod/net/OkDns.java index c1af4ded2..5c4a3ad13 100644 --- a/catvod/src/main/java/com/github/catvod/net/OkDns.java +++ b/catvod/src/main/java/com/github/catvod/net/OkDns.java @@ -10,7 +10,9 @@ import java.net.UnknownHostException; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import kotlin._Assertions; import okhttp3.Dns; @@ -37,13 +39,19 @@ public class OkDns implements Dns { } public void addAll(List hosts) { - hosts.stream().map(host -> host.split("=", 2)).filter(splits -> splits.length == 2).forEach(splits -> map.put(splits[0], splits[1])); + map.putAll(hosts.stream().filter(Objects::nonNull).map(host -> host.split("=", 2)).filter(splits -> splits.length == 2).collect(Collectors.toMap(s -> s[0].trim(), s -> s[1].trim(), (oldHost, newHost) -> newHost))); + } + + private String get(String hostname) { + String target = map.get(hostname); + if (target != null) return target; + for (Map.Entry entry : map.entrySet()) if (Util.containOrMatch(hostname, entry.getKey())) return entry.getValue(); + return hostname; } @NonNull @Override public List lookup(@NonNull String hostname) throws UnknownHostException { - for (Map.Entry entry : map.entrySet()) if (Util.containOrMatch(hostname, entry.getKey())) hostname = entry.getValue(); - return (doh != null ? doh : Dns.SYSTEM).lookup(hostname); + return (doh != null ? doh : Dns.SYSTEM).lookup(get(hostname)); } }