fixed review findings

This commit is contained in:
Sebastian Sdorra
2020-05-20 11:18:58 +02:00
parent 033c5168a9
commit 12355f2754
2 changed files with 30 additions and 6 deletions

View File

@@ -59,14 +59,26 @@ const normalizePath = (path: string) => {
stack.push(part)
}
}
return stack.join("/")
const normalizedPath = stack.join("/")
if (normalizedPath.startsWith("/")) {
return normalizedPath;
}
return "/" + normalizedPath;
};
const isAbsolute = (link: string) => {
return link.startsWith("/");
};
const isSubDirectoryOf = (basePath: string, currentPath: string) => {
return currentPath.startsWith(basePath);
};
export const createLocalLink = (basePath: string, currentPath: string, link: string) => {
if (link.startsWith("/")) {
if (isAbsolute(link)) {
return join(basePath, link);
}
if (!currentPath.startsWith(basePath)) {
if (!isSubDirectoryOf(basePath, currentPath)) {
return join(basePath, link);
}
let path = currentPath;