























@@ -36,7 +36,40 @@ function parseProxyTargetUrl(targetUrl: string | URL): URL | undefined {
3636}
3737}
383839+function normalizeProxyHostname(hostname: string): string {
40+let normalized = hostname.toLowerCase();
41+if (normalized.startsWith("[") && normalized.endsWith("]")) {
42+normalized = normalized.slice(1, -1);
43+}
44+return normalized.endsWith(".") ? normalized.slice(0, -1) : normalized;
45+}
46+47+function parseNoProxyEntry(entry: string): { hostname: string; port: number } {
48+const bracketed = entry.match(/^\[([^\]]+)\](?::(\d+))?$/);
49+if (bracketed) {
50+return {
51+hostname: normalizeProxyHostname(bracketed[1] ?? ""),
52+port: bracketed[2] ? Number.parseInt(bracketed[2], 10) : 0,
53+};
54+}
55+56+const firstColon = entry.indexOf(":");
57+const lastColon = entry.lastIndexOf(":");
58+if (firstColon > -1 && firstColon === lastColon) {
59+const portRaw = entry.slice(lastColon + 1);
60+if (/^\d+$/.test(portRaw)) {
61+return {
62+hostname: normalizeProxyHostname(entry.slice(0, lastColon)),
63+port: Number.parseInt(portRaw, 10),
64+};
65+}
66+}
67+68+return { hostname: normalizeProxyHostname(entry), port: 0 };
69+}
70+3971function shouldProxyHostname(hostname: string, port: number): boolean {
72+const normalizedHostname = normalizeProxyHostname(hostname);
4073const noProxy = getProxyEnv("no_proxy").toLowerCase();
4174if (!noProxy) {
4275return true;
@@ -50,21 +83,21 @@ function shouldProxyHostname(hostname: string, port: number): boolean {
5083return true;
5184}
528553-const parsedProxy = proxy.match(/^(.+):(\d+)$/);
54-let proxyHostname = parsedProxy ? parsedProxy[1] : proxy;
55-const proxyPort = parsedProxy ? Number.parseInt(parsedProxy[2], 10) : 0;
86+const parsedProxy = parseNoProxyEntry(proxy);
87+let proxyHostname = parsedProxy.hostname;
88+const proxyPort = parsedProxy.port;
5689if (proxyPort && proxyPort !== port) {
5790return true;
5891}
59926093if (!/^[.*]/.test(proxyHostname)) {
61-return hostname !== proxyHostname;
94+return normalizedHostname !== proxyHostname;
6295}
63966497if (proxyHostname.startsWith("*")) {
6598proxyHostname = proxyHostname.slice(1);
6699}
67-return !hostname.endsWith(proxyHostname);
100+return !normalizedHostname.endsWith(proxyHostname);
68101});
69102}
70103@@ -75,7 +108,7 @@ function getProxyForUrl(targetUrl: string | URL): string {
75108}
7610977110const protocol = parsedUrl.protocol.split(":", 1)[0];
78-const hostname = parsedUrl.host.replace(/:\d*$/, "");
111+const hostname = parsedUrl.hostname;
79112const port = Number.parseInt(parsedUrl.port, 10) || DEFAULT_PROXY_PORTS[protocol] || 0;
80113if (!shouldProxyHostname(hostname, port)) {
81114return "";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。