fix: handling default port in proxy configuration (#1420)

This commit is contained in:
Whitewater
2024-11-05 03:37:11 -08:00
committed by GitHub
2 changed files with 10 additions and 2 deletions
+8
View File
@@ -40,6 +40,14 @@ describe("proxy", () => {
expect(result).toBe(true)
})
it("should handle default port", () => {
// https://github.com/RSSNext/Follow/issues/1197
const proxy = "http://example.com:80"
const result = setProxyConfig(proxy)
expect(store.set).toHaveBeenCalledWith("proxy", "http://example.com")
expect(result).toBe(true)
})
it("should return false for invalid proxy", () => {
const proxy = "invalid-proxy"
const result = setProxyConfig(proxy)
+2 -2
View File
@@ -43,12 +43,12 @@ const normalizeProxyUri = (userProxy: string) => {
try {
const proxyUrl = new URL(firstInput)
if (!URL_SCHEME.has(proxyUrl.protocol) || !proxyUrl.hostname || !proxyUrl.port) {
if (!URL_SCHEME.has(proxyUrl.protocol) || !proxyUrl.hostname) {
return
}
// There are multiple ways to specify a proxy in Electron,
// but for security reasons, we only support simple proxy URLs for now.
return `${proxyUrl.protocol}//${proxyUrl.hostname}:${proxyUrl.port}`
return `${proxyUrl.protocol}//${proxyUrl.hostname}${proxyUrl.port ? `:${proxyUrl.port}` : ""}`
} catch {
return
}