diff --git a/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts b/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts index 02ab2623cc104..1aab8cc3243ef 100644 --- a/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts +++ b/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts @@ -20,7 +20,10 @@ import { useEffect, useState } from 'react'; import { ResourceFilter } from 'teleport/services/agents'; -import { encodeUrlQueryParams } from 'teleport/components/hooks/useUrlFiltering'; +import { + decodeUrlQueryParam, + encodeUrlQueryParams, +} from 'teleport/components/hooks/useUrlFiltering'; export default function useServersideSearchPanel({ pathname, @@ -90,15 +93,6 @@ export default function useServersideSearchPanel({ }; } -function decodeUrlQueryParam(param: string) { - // Prevents URI malformed error by replacing lone % with %25 - const decodedQuery = decodeURIComponent( - param.replace(/%(?![0-9][0-9a-fA-F]+)/g, '%25') - ); - - return decodedQuery; -} - export type HookProps = { pathname: string; replaceHistory: (path: string) => void; diff --git a/web/packages/teleport/src/components/hooks/useUrlFiltering/decodeUrlQueryParam.ts b/web/packages/teleport/src/components/hooks/useUrlFiltering/decodeUrlQueryParam.ts new file mode 100644 index 0000000000000..93de5c951e419 --- /dev/null +++ b/web/packages/teleport/src/components/hooks/useUrlFiltering/decodeUrlQueryParam.ts @@ -0,0 +1,30 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/** + * calls native decodeURIComponent under the hood but goes + * one step further by replacing lone % with %25 + * to prevent URI malformed error. + */ +export function decodeUrlQueryParam(param: string) { + const decodedQuery = decodeURIComponent( + param.replace(/%(?![0-9][0-9a-fA-F]+)/g, '%25') + ); + + return decodedQuery; +} diff --git a/web/packages/teleport/src/components/hooks/useUrlFiltering/index.ts b/web/packages/teleport/src/components/hooks/useUrlFiltering/index.ts index 050823729982b..15dbd7ecb7b42 100644 --- a/web/packages/teleport/src/components/hooks/useUrlFiltering/index.ts +++ b/web/packages/teleport/src/components/hooks/useUrlFiltering/index.ts @@ -18,3 +18,4 @@ export { useUrlFiltering } from './useUrlFiltering'; export { encodeUrlQueryParams } from './encodeUrlQueryParams'; +export { decodeUrlQueryParam } from './decodeUrlQueryParam';