From 79703f8ad20a3563a175efc3e6b9368476287204 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Wed, 13 May 2026 14:17:11 -0700 Subject: [PATCH] fix: preserve trailing slash in joinURL when path is "/" (#134) --- src/_utils.ts | 4 ++-- test/_utils.test.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_utils.ts b/src/_utils.ts index 5c4ea97..85898ae 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -184,8 +184,8 @@ export function joinURL(base: string | undefined, path: string | undefined): str if (!base || base === "/") { return path || "/"; } - if (!path || path === "/") { - return base || "/"; + if (!path) { + return base; } // eslint-disable-next-line unicorn/prefer-at const baseHasTrailing = base[base.length - 1] === "/"; diff --git a/test/_utils.test.ts b/test/_utils.test.ts index 9e1026f..d110446 100644 --- a/test/_utils.test.ts +++ b/test/_utils.test.ts @@ -609,6 +609,14 @@ describe("lib/http-proxy/common.js", () => { it("should concat when base has trailing slash and path has no leading slash", () => { expect(common.joinURL("/base/", "path")).to.eql("/base/path"); }); + + it("should preserve trailing slash when path is exactly /", () => { + expect(common.joinURL("/maildev", "/")).to.eql("/maildev/"); + }); + + it("should keep a single trailing slash when both base ends and path is /", () => { + expect(common.joinURL("/maildev/", "/")).to.eql("/maildev/"); + }); }); describe("#rewriteCookieProperty", () => {