X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f0a64666816383d2641d5fa7ea22019441ac4464..fe409e309257b4cb9c255c7e8b74d1f97d7297f6:/src/common/url.ts diff --git a/src/common/url.ts b/src/common/url.ts index 9789b65eff..db12cb8ea8 100644 --- a/src/common/url.ts +++ b/src/common/url.ts @@ -1,5 +1,9 @@ +// 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 safeName = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]'); const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)'); const results = regex.exec(search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); @@ -9,7 +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) => { + try { + return path.split('/').map(encodeURIComponent).join('/'); + } catch(e) {} + + return path; +}; + +export const customDecodeURI = (path: string) => { + try { + return path.split('%2F').map(decodeURIComponent).join('%2F'); + } catch(e) {} + + return path; +};