From 07b47fbf3a1103bb4216accaf8287c42a76d6af0 Mon Sep 17 00:00:00 2001 From: "Apple\\Apple" Date: Tue, 10 Jun 2025 12:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(api):=20enhance=20URL=20vali?= =?UTF-8?q?dation=20to=20support=20IP=20addresses=20and=20ports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update URL regex pattern to accept both domain names and IP addresses - Add support for IPv4 addresses with optional port numbers - Improve validation to handle formats like http://192.168.1.1:8080 - Add comprehensive comments explaining supported URL formats - Maintain backward compatibility with existing domain-based URLs Fixes issue where IP-based URLs were incorrectly rejected as invalid format. --- setting/api_info.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setting/api_info.go b/setting/api_info.go index 0d7ffcfd..552dabf5 100644 --- a/setting/api_info.go +++ b/setting/api_info.go @@ -33,8 +33,10 @@ func ValidateApiInfo(apiInfoStr string) error { "violet": true, "grey": true, } - // URL正则表达式 - urlRegex := regexp.MustCompile(`^https?://[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(/.*)?$`) + // URL正则表达式,支持域名和IP地址格式 + // 域名格式:https://example.com 或 https://sub.example.com:8080 + // IP地址格式:https://192.168.1.1 或 https://192.168.1.1:8080 + urlRegex := regexp.MustCompile(`^https?://(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?::[0-9]{1,5})?(?:/.*)?$`) for i, apiInfo := range apiInfoList { // 检查必填字段