17337: Added more tests, fixed whitespace issue
[arvados-workbench2.git] / src / common / url.ts
index 9789b65effb6b47d6ed14c0589cb39b2b032c2a4..6223485eabee6908fa363ea94e7345c1c54d7822 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,10 @@ export function normalizeURLPath(url: string) {
     }
     return u.toString();
 }
+
+export const escapeHashIfRequired = (name: string, defaultTransformation?: Function) =>
+    name.indexOf('#') > -1 ?
+        encodeURIComponent(name) :
+        defaultTransformation ?
+            defaultTransformation(name) :
+            name;
\ No newline at end of file