From eb918ca09f23b00a7a6297086a773aa274619e25 Mon Sep 17 00:00:00 2001 From: OneWay Date: Sun, 20 Sep 2026 21:45:07 +0800 Subject: [PATCH] fix: accept host:port in dictionary source URLs URL validation rejected any host containing a colon, so sources on non-standard ports could not be added. Strip the optional :port from the host before applying the domain checks and validate the port range (1-65535); the port is kept intact through template normalization and URL building. --- .../research/core/domain/model/DictionarySource.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt b/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt index 707d92e..7df0ce1 100644 --- a/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt +++ b/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt @@ -132,8 +132,15 @@ data class DictionarySource( val parts = afterProtocol.split("/") if (parts.size < 2) return false - val domain = parts[0] - if (domain.isEmpty()) return false + val hostWithPort = parts[0] + if (hostWithPort.isEmpty()) return false + + val colonIndex = hostWithPort.lastIndexOf(':') + if (colonIndex >= 0) { + val port = hostWithPort.substring(colonIndex + 1).toIntOrNull() + if (port == null || port !in 1..65535) return false + } + val domain = if (colonIndex >= 0) hostWithPort.substring(0, colonIndex) else hostWithPort if (domain != "localhost" && !domain.contains(".")) return false val filename = parts.last()