17337: Added custom encode functions with tests
[arvados-workbench2.git] / src / common / url.ts
index 9789b65effb6b47d6ed14c0589cb39b2b032c2a4..0d2549c1b9fc55cb6b123833ab30e29d4e3aa083 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 export function getUrlParameter(search: string, name: string) {
     const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
     const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)');
@@ -13,3 +17,15 @@ export function normalizeURLPath(url: string) {
     }
     return u.toString();
 }
+
+export const customEncodeURI = (path: string) => {
+    return encodeURIComponent(path.replace(/%2F/g, '/'));
+};
+
+export const customDecodeURI = (path: string) => {
+    return decodeURIComponent(path.replace(/\//g, '%2F'));
+};
+
+export const encodeHash = (path: string) => {
+    return path.replace(/#/g, '%23');
+};
\ No newline at end of file