Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Fix: Path resolution when base path is null/empty #160

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/util/composeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
};
Expand Down