Sfoglia il codice sorgente

🔧 fix(api): enhance URL validation to support IP addresses and ports

- 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.
Apple\Apple 9 mesi fa
parent
commit
07b47fbf3a
1 ha cambiato i file con 4 aggiunte e 2 eliminazioni
  1. 4 2
      setting/api_info.go

+ 4 - 2
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 {
 		// 检查必填字段