From 073fd5e4996dc8f4511abaf30d0dcf43c623a6a2 Mon Sep 17 00:00:00 2001 From: Manishalexin Date: Mon, 28 Oct 2019 22:55:12 +0530 Subject: [PATCH] Fix: Path resolution when base is null/empty --- src/util/composeUrl.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/composeUrl.ts b/src/util/composeUrl.ts index 93309437..e3d78029 100644 --- a/src/util/composeUrl.ts +++ b/src/util/composeUrl.ts @@ -2,6 +2,11 @@ import url from "url"; export const composeUrl = (base: string = "", parentPath: string = "", path: string = ""): string => { const composedPath = composePath(parentPath, path); + /* If the base is empty, preceding slash will be trimmed during composition */ + if (base === "" && composedPath.startsWith("/")) { + return composedPath; + } + /* If the base contains a trailing slash, it will be trimmed during composition */ return base!.endsWith("/") ? `${base!.slice(0, -1)}${composedPath}` : `${base}${composedPath}`; };