From 6df1cc763802b3563aadf2cc1d19d6de89a4dacb Mon Sep 17 00:00:00 2001 From: Younes Aassila <47226184+younesaassila@users.noreply.github.com> Date: Fri, 7 Feb 2025 16:15:33 +0100 Subject: [PATCH] Improve code --- src/common/ts/proxyInfo.ts | 4 ++-- src/common/ts/proxySettings.ts | 2 +- src/options/options.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/ts/proxyInfo.ts b/src/common/ts/proxyInfo.ts index 1e46349..1994f5d 100644 --- a/src/common/ts/proxyInfo.ts +++ b/src/common/ts/proxyInfo.ts @@ -14,9 +14,9 @@ export function getProxyInfoFromUrl( ): ProxyInfo & { host: string; port: number } { let type: ProxyType | undefined = undefined; if (url.includes("://")) { - const [protocol, urlWithoutProtocol] = url.split("://", 2); + const [protocol] = url.split("://", 1); type = protocol as ProxyType; - url = urlWithoutProtocol; + url = url.substring(protocol.length + 3, url.length); } const lastIndexOfAt = url.lastIndexOf("@"); diff --git a/src/common/ts/proxySettings.ts b/src/common/ts/proxySettings.ts index 39f3de5..366e495 100644 --- a/src/common/ts/proxySettings.ts +++ b/src/common/ts/proxySettings.ts @@ -15,8 +15,8 @@ const PROXY_TYPE_MAP: Readonly> = Object.freeze({ direct: "DIRECT", http: "PROXY", https: "HTTPS", - socks4: "SOCKS4", socks: "SOCKS5", + socks4: "SOCKS4", }); export function updateProxySettings(requestFilter?: ProxyRequestType[]) { diff --git a/src/options/options.ts b/src/options/options.ts index 75e4a38..bee4b2e 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -346,13 +346,13 @@ function isOptimizedProxyUrlAllowed(url: string): AllowedResult { } if (url.includes("://")) { - const [protocol, urlWithoutProtocol] = url.split("://", 2); + const [protocol] = url.split("://", 1); if (!store.state.allowOtherProxyProtocols) { return [false, "Proxy URLs must not contain a protocol (e.g. 'http://')"]; } else if (!["http", "https", "socks", "socks4"].includes(protocol)) { return [false, `'${protocol}' is not a supported protocol`]; } - url = urlWithoutProtocol; + url = url.substring(protocol.length + 3, url.length); } if (url.includes("/")) {