Merge branch '19153-sharing-links-inline' into main. Closes #19153
[arvados-workbench2.git] / src / common / url.ts
index 0d2549c1b9fc55cb6b123833ab30e29d4e3aa083..db12cb8ea8805a86c14e057e957e3d513cc00acc 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 export function getUrlParameter(search: string, name: string) {
-    const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
+    const safeName = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
     const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)');
     const results = regex.exec(search);
     return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
@@ -13,19 +13,23 @@ export function normalizeURLPath(url: string) {
     const u = new URL(url);
     u.pathname = u.pathname.replace(/\/\//, '/');
     if (u.pathname[u.pathname.length - 1] === '/') {
-        u.pathname = u.pathname.substr(0, u.pathname.length - 1);
+        u.pathname = u.pathname.substring(0, u.pathname.length - 1);
     }
     return u.toString();
 }
 
 export const customEncodeURI = (path: string) => {
-    return encodeURIComponent(path.replace(/%2F/g, '/'));
+    try {
+        return path.split('/').map(encodeURIComponent).join('/');
+    } catch(e) {}
+
+    return path;
 };
 
 export const customDecodeURI = (path: string) => {
-    return decodeURIComponent(path.replace(/\//g, '%2F'));
-};
+    try {
+        return path.split('%2F').map(decodeURIComponent).join('%2F');
+    } catch(e) {}
 
-export const encodeHash = (path: string) => {
-    return path.replace(/#/g, '%23');
-};
\ No newline at end of file
+    return path;
+};