X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8297f0f273e326e64145a48266805b0b3d073c32..f75b0aa3966895160535bad24b05c1a763665a5a:/src/common/url.ts diff --git a/src/common/url.ts b/src/common/url.ts index 0d2549c1b9..db12cb8ea8 100644 --- a/src/common/url.ts +++ b/src/common/url.ts @@ -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; +};