Pārlūkot izejas kodu

Resolve some issues with parent directories at the top of a url path

Jason Grout 4 gadi atpakaļ
vecāks
revīzija
470964a5bb
1 mainītis faili ar 3 papildinājumiem un 6 dzēšanām
  1. 3 6
      packages/coreutils/src/url.ts

+ 3 - 6
packages/coreutils/src/url.ts

@@ -46,12 +46,9 @@ export namespace URLExt {
   export function join(...parts: string[]): string {
     const first = urlparse(parts[0], {});
     const prefix = `${first.protocol}${first.slashes ? '//' : ''}${first.auth}${first.host}`;
-    let path = posix.join(first.pathname, ...parts.slice(1));
-    if (path === '.') {
-      path = '';
-    }
-    // Put in a slash between the prefix and path if needed
-    return `${prefix}${!!prefix && !!path && path[0] !== '/' ? '/' : ''}${path}`;
+    // If there was a prefix, then the first path must start at the root.
+    const path = posix.join(`${!!prefix && first.pathname[0] !== '/' ? '/' : ''}${first.pathname}`, ...parts.slice(1));
+    return `${prefix}${path === '.' ? '' : path}`;
   }
 
   /**