diff options
-rw-r--r-- | src/env_loader.zig | 12 | ||||
-rw-r--r-- | test/js/bun/http/proxy.test.js | 29 |
2 files changed, 38 insertions, 3 deletions
diff --git a/src/env_loader.zig b/src/env_loader.zig index 9d0c69d04..2d467371a 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -102,18 +102,24 @@ pub const Loader = struct { if (url.isHTTP()) { if (this.map.get("http_proxy") orelse this.map.get("HTTP_PROXY")) |proxy| { - if (proxy.len > 0) http_proxy = URL.parse(proxy); + if (proxy.len > 0 and !strings.eqlComptime(proxy, "\"\"") and !strings.eqlComptime(proxy, "''")) { + http_proxy = URL.parse(proxy); + } } } else { if (this.map.get("https_proxy") orelse this.map.get("HTTPS_PROXY")) |proxy| { - if (proxy.len > 0) http_proxy = URL.parse(proxy); + if (proxy.len > 0 and !strings.eqlComptime(proxy, "\"\"") and !strings.eqlComptime(proxy, "''")) { + http_proxy = URL.parse(proxy); + } } } // NO_PROXY filter if (http_proxy != null) { if (this.map.get("no_proxy") orelse this.map.get("NO_PROXY")) |no_proxy_text| { - if (no_proxy_text.len == 0) return http_proxy; + if (no_proxy_text.len == 0 or strings.eqlComptime(no_proxy_text, "\"\"") or strings.eqlComptime(no_proxy_text, "''")) { + return http_proxy; + } var no_proxy_list = std.mem.split(u8, no_proxy_text, ","); var next = no_proxy_list.next(); diff --git a/test/js/bun/http/proxy.test.js b/test/js/bun/http/proxy.test.js index 48595a2ac..433adfb83 100644 --- a/test/js/bun/http/proxy.test.js +++ b/test/js/bun/http/proxy.test.js @@ -1,7 +1,9 @@ import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { gc } from "harness"; import fs from "fs"; +import { tmpdir } from "os"; import path from "path"; +import { bunExe } from "harness"; let proxy, auth_proxy, server; @@ -168,3 +170,30 @@ it("proxy non-TLS auth can fail", async () => { } } }); + +it.each([ + [undefined, undefined], + ["", ""], + ["''", "''"], + ['""', '""'], +])("test proxy env, http_proxy=%s https_proxy=%s", async (http_proxy, https_proxy) => { + const path = `${tmpdir()}/bun-test-http-proxy-env-${Date.now()}.ts`; + fs.writeFileSync(path, 'await fetch("https://example.com");'); + + const { stdout, stderr, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "run", path], + env: { + http_proxy: http_proxy, + https_proxy: https_proxy, + }, + stdout: "pipe", + stderr: "pipe", + }); + + try { + expect(stderr.includes("FailedToOpenSocket: Was there a typo in the url or port?")).toBe(false); + expect(exitCode).toBe(0); + } finally { + fs.unlinkSync(path); + } +}); |