Skip to content

Commit 0d4bfd7

Browse files
committed
Enhance proxy and SOCKS5 address validation in index.js to support comma-separated formats. Updated validation logic to check multiple addresses and improved comments for clarity.
1 parent ea708d2 commit 0d4bfd7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,23 @@ export default {
9494

9595
// 验证proxyip格式
9696
if (urlPROXYIP) {
97-
// 验证格式: domain:port 或 ip:port
97+
// 验证格式: domain:port 或 ip:port,支持逗号分隔
9898
const proxyPattern = /^([a-zA-Z0-9][-a-zA-Z0-9.]*(\.[a-zA-Z0-9][-a-zA-Z0-9.]*)+|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[0-9a-fA-F:]+\]):\d{1,5}$/;
99-
if (!proxyPattern.test(urlPROXYIP)) {
99+
const proxyAddresses = urlPROXYIP.split(',').map(addr => addr.trim());
100+
const isValid = proxyAddresses.every(addr => proxyPattern.test(addr));
101+
if (!isValid) {
100102
console.warn('无效的proxyip格式:', urlPROXYIP);
101103
urlPROXYIP = null;
102104
}
103105
}
104106

105107
// 验证socks5格式
106108
if (urlSOCKS5) {
107-
// 基本验证 - 可以根据实际格式要求调整
109+
// 基本验证 - 支持逗号分隔的多个地址
108110
const socks5Pattern = /^(([^:@]+:[^:@]+@)?[a-zA-Z0-9][-a-zA-Z0-9.]*(\.[a-zA-Z0-9][-a-zA-Z0-9.]*)+|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d{1,5}$/;
109-
if (!socks5Pattern.test(urlSOCKS5)) {
111+
const socks5Addresses = urlSOCKS5.split(',').map(addr => addr.trim());
112+
const isValid = socks5Addresses.every(addr => socks5Pattern.test(addr));
113+
if (!isValid) {
110114
console.warn('无效的socks5格式:', urlSOCKS5);
111115
urlSOCKS5 = null;
112116
}

0 commit comments

Comments
 (0)