Browse Source

Decode url paths more thoroughly before passing them into contents api functions.

Fixes #9895

There still is some work to do here to make it very clear where we are dealing with urls (which may have query parameters, protocol, etc.), where we are dealing with url paths (i.e., a url component, just the path portion of the url), and where we are dealing with just plain posix-style paths. For example, resolver.isLocal seems to conflate all three concepts.
Jason Grout 4 years ago
parent
commit
429e01986c
2 changed files with 6 additions and 6 deletions
  1. 5 5
      packages/rendermime/src/registry.ts
  2. 1 1
      packages/rendermime/src/renderers.ts

+ 5 - 5
packages/rendermime/src/registry.ts

@@ -364,14 +364,14 @@ export namespace RenderMimeRegistry {
      * Get the download url of a given absolute url path.
      *
      * #### Notes
-     * This URL may include a query parameter.
+     * The returned URL may include a query parameter.
      */
-    async getDownloadUrl(url: string): Promise<string> {
-      if (this.isLocal(url)) {
+    async getDownloadUrl(urlPath: string): Promise<string> {
+      if (this.isLocal(urlPath)) {
         // decode url->path before passing to contents api
-        return this._contents.getDownloadUrl(decodeURI(url));
+        return this._contents.getDownloadUrl(decodeURIComponent(urlPath));
       }
-      return url;
+      return urlPath;
     }
 
     /**

+ 1 - 1
packages/rendermime/src/renderers.ts

@@ -803,7 +803,7 @@ namespace Private {
       .resolveUrl(href)
       .then(urlPath => {
         // decode encoded url from url to api path
-        const path = decodeURI(urlPath);
+        const path = decodeURIComponent(urlPath);
         // Handle the click override.
         if (linkHandler) {
           linkHandler.handleLink(anchor, path, hash);