From 3bb8c0c3ab79fa26f2230bdaaf6a072e71a20a0e Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 11 Jan 2022 14:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/utils/NetworkUtils.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt index cee94904d..477a2e11f 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -140,7 +140,7 @@ object NetworkUtils { } fun getBaseUrl(url: String?): String? { - if (url == null || !url.startsWith("http")) return null + url ?: return null val index = url.indexOf("/", 9) return if (index == -1) { url @@ -156,14 +156,20 @@ object NetworkUtils { */ fun getSubDomain(url: String): String { val baseUrl = getBaseUrl(url) ?: return url - return kotlin.runCatching { - val mURL = URL(baseUrl) - val host: String = mURL.host - //判断是否为ip - if (isIPAddress(host)) return baseUrl - //PublicSuffixDatabase处理域名 - PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl - }.getOrDefault(url) + return if (url.startsWith("http://", true) + || url.startsWith("https://", true) + ) { + kotlin.runCatching { + val mURL = URL(baseUrl) + val host: String = mURL.host + //判断是否为ip + if (isIPAddress(host)) return baseUrl + //PublicSuffixDatabase处理域名 + PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl + }.getOrDefault(baseUrl) + } else { + baseUrl + } } /**