17337: Added more tests to cover edge cases
[arvados-workbench2.git] / src / common / webdav.ts
index e896a207e7c5708c7b9948592606cf6ae3fbae7d..0b77f8c33262e9b7b0b284b4da682d6ec58ceb85 100644 (file)
@@ -2,6 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { customEncodeURI } from "./url";
+
 export class WebDAV {
 
     defaults: WebDAVDefaults = {
@@ -75,7 +77,14 @@ export class WebDAV {
             r.open(config.method,
                 `${this.defaults.baseURL
                     ? this.defaults.baseURL+'/'
-                    : ''}${encodeURIComponent(config.url)}`);
+                    : ''}${customEncodeURI(config.url)}`);
+
+            if (config.headers && config.headers.Destination) {
+                const regexp = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/;
+                const match = decodeURIComponent(config.headers.Destination).match(regexp) || {};
+                config.headers.Destination = `${match[1]}${match[2]}${customEncodeURI(match[3])}`;
+            }
+
             const headers = { ...this.defaults.headers, ...config.headers };
             Object
                 .keys(headers)