From 945990ebaadd08fb3da7b863d95b1910524a1a66 Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Wed, 4 Mar 2020 17:15:59 -0500 Subject: [PATCH] Update more encoding uses --- .../public/state_management/url/kbn_url_storage.ts | 1 - .../public/components/shared/Links/url_helpers.ts | 4 ++-- .../public/app/services/routing.js | 4 ++-- .../analytics_job_exploration.tsx | 2 +- .../plugins/ml/public/application/util/url_state.ts | 5 +++-- .../ml_host_conditional_container.tsx | 8 +++----- .../ml_network_conditional_container.tsx | 10 +++++----- .../siem/public/components/url_state/helpers.ts | 13 +++++-------- .../log_analysis_results/analyze_in_ml_button.tsx | 5 ++--- x-pack/plugins/infra/public/utils/url_state.tsx | 10 ++++------ 10 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/plugins/kibana_utils/public/state_management/url/kbn_url_storage.ts b/src/plugins/kibana_utils/public/state_management/url/kbn_url_storage.ts index 9003427d88ab7..0bca1f7b6e8bd 100644 --- a/src/plugins/kibana_utils/public/state_management/url/kbn_url_storage.ts +++ b/src/plugins/kibana_utils/public/state_management/url/kbn_url_storage.ts @@ -18,7 +18,6 @@ */ import { format as formatUrl } from 'url'; -// import { stringify } from 'querystring'; import { createBrowserHistory, History } from 'history'; import { decodeState, encodeState } from '../state_encoder'; import { getCurrentUrl, parseUrl, parseUrlHash } from './parse'; diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/url_helpers.ts b/x-pack/legacy/plugins/apm/public/components/shared/Links/url_helpers.ts index b592cfe6c12b3..7b2d8cf56f889 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/url_helpers.ts +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/url_helpers.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { parse, stringify } from 'querystring'; +import { parse } from 'querystring'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { LocalUIFilterName } from '../../../../../../../plugins/apm/server/lib/ui_filters/local_ui_filters/config'; import { url } from '../../../../../../../../src/plugins/kibana_utils/public'; @@ -18,7 +18,7 @@ export function fromQuery(query: Record) { encodeURIComponent(value).replace(/%3A/g, ':') ); - return stringify(encodedQuery); + return url.makeUrlFromQuery(encodedQuery); } export type APMQueryParams = { diff --git a/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/routing.js b/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/routing.js index febe5bfaf6642..f40e3c4dd5938 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/routing.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/routing.js @@ -24,8 +24,8 @@ const queryParamsFromObject = (params, encodeParams = false) => { const paramStr = stringify( params, - '&', - '=', + undefined, + undefined, encodeParams ? {} : { diff --git a/x-pack/legacy/plugins/ml/public/application/routing/routes/data_frame_analytics/analytics_job_exploration.tsx b/x-pack/legacy/plugins/ml/public/application/routing/routes/data_frame_analytics/analytics_job_exploration.tsx index 62da03c654fb3..c520d6b0a8d96 100644 --- a/x-pack/legacy/plugins/ml/public/application/routing/routes/data_frame_analytics/analytics_job_exploration.tsx +++ b/x-pack/legacy/plugins/ml/public/application/routing/routes/data_frame_analytics/analytics_job_exploration.tsx @@ -34,7 +34,7 @@ export const analyticsJobExplorationRoute: MlRoute = { const PageWrapper: FC = ({ location, deps }) => { const { context } = useResolver('', undefined, deps.config, basicResolvers(deps)); - const { _g }: Record = parse(location.search); + const { _g }: Record = parse(location.search.substring(1)); let globalState: any = null; try { diff --git a/x-pack/legacy/plugins/ml/public/application/util/url_state.ts b/x-pack/legacy/plugins/ml/public/application/util/url_state.ts index 25fd022a3ed73..cbca2a494c730 100644 --- a/x-pack/legacy/plugins/ml/public/application/util/url_state.ts +++ b/x-pack/legacy/plugins/ml/public/application/util/url_state.ts @@ -9,6 +9,7 @@ import { useCallback } from 'react'; import { isEqual } from 'lodash'; import { decode, encode } from 'rison-node'; import { useHistory, useLocation } from 'react-router-dom'; +import { url } from '../../../../../../../src/plugins/kibana_utils/common/url'; import { Dictionary } from '../../../common/types/common'; @@ -83,7 +84,7 @@ export const useUrlState = (accessor: string): UrlState => { } try { - const oldLocationSearch = stringify(parsedQueryString); + const oldLocationSearch = url.makeUrlFromQuery(parsedQueryString); Object.keys(urlState).forEach(a => { if (isRisonSerializationRequired(a)) { @@ -92,7 +93,7 @@ export const useUrlState = (accessor: string): UrlState => { parsedQueryString[a] = urlState[a]; } }); - const newLocationSearch = stringify(parsedQueryString); + const newLocationSearch = url.makeUrlFromQuery(parsedQueryString); if (oldLocationSearch !== newLocationSearch) { history.push({ diff --git a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_host_conditional_container.tsx b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_host_conditional_container.tsx index c65ac17690952..7ba56e85ab50d 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_host_conditional_container.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_host_conditional_container.tsx @@ -37,7 +37,7 @@ export const MlHostConditionalContainer = React.memo(({ if (queryStringDecoded.query != null) { queryStringDecoded.query = replaceKQLParts(queryStringDecoded.query); } - const reEncoded = stringify(urlUtils.encodeQuery(queryStringDecoded)); + const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded); return ; }} /> @@ -49,15 +49,13 @@ export const MlHostConditionalContainer = React.memo(({ params: { hostName }, }, }) => { - const queryStringDecoded = parse(location.search.substring(1), { - sort: false, - }) as Required; + const queryStringDecoded = parse(location.search.substring(1)) as Required; if (queryStringDecoded.query != null) { queryStringDecoded.query = replaceKQLParts(queryStringDecoded.query); } if (emptyEntity(hostName)) { - const reEncoded = stringify(urlUtils.encodeQuery(queryStringDecoded)); + const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded); return ( diff --git a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_network_conditional_container.tsx b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_network_conditional_container.tsx index cc41301b4f898..8d9d0f874c3ab 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_network_conditional_container.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/conditional_links/ml_network_conditional_container.tsx @@ -5,7 +5,7 @@ */ // eslint-disable-next-line import/no-nodejs-modules -import { parse, stringify } from 'querystring'; +import { parse } from 'querystring'; import React from 'react'; import { Redirect, Route, Switch, RouteComponentProps } from 'react-router-dom'; @@ -37,7 +37,7 @@ export const MlNetworkConditionalContainer = React.memo; }} @@ -57,7 +57,7 @@ export const MlNetworkConditionalContainer = React.memo; } else if (multipleEntities(ip)) { @@ -67,10 +67,10 @@ export const MlNetworkConditionalContainer = React.memo; } else { - const reEncoded = stringify(urlUtils.encodeQuery(queryStringDecoded)); + const reEncoded = urlUtils.makeUrlFromQuery(queryStringDecoded); return ; } }} diff --git a/x-pack/legacy/plugins/siem/public/components/url_state/helpers.ts b/x-pack/legacy/plugins/siem/public/components/url_state/helpers.ts index 1c8fa1b56187e..e1086a95bf8a3 100644 --- a/x-pack/legacy/plugins/siem/public/components/url_state/helpers.ts +++ b/x-pack/legacy/plugins/siem/public/components/url_state/helpers.ts @@ -57,7 +57,7 @@ export const replaceStateKeyInQueryString = (stateKey: string, urlState: T) = if (urlState == null || (typeof urlState === 'string' && urlState === '')) { delete previousQueryValues[stateKey]; - return stringify(url.encodeQuery(previousQueryValues)); + return url.makeUrlFromQuery(previousQueryValues); } // ಠ_ಠ Code was copied from x-pack/legacy/plugins/infra/public/utils/url_state.tsx ಠ_ಠ @@ -65,13 +65,10 @@ export const replaceStateKeyInQueryString = (stateKey: string, urlState: T) = const encodedUrlState = typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined; - return stringify( - url.encodeQuery({ - ...previousQueryValues, - [stateKey]: encodedUrlState, - }), - { sort: false, encode: false } - ); + return url.makeUrlFromQuery({ + ...previousQueryValues, + [stateKey]: encodedUrlState, + }); }; export const replaceQueryStringInLocation = ( diff --git a/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx b/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx index 31c097b983240..63906aff5e2d1 100644 --- a/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx +++ b/x-pack/plugins/infra/public/components/logging/log_analysis_results/analyze_in_ml_button.tsx @@ -9,7 +9,6 @@ import { FormattedMessage } from '@kbn/i18n/react'; import React from 'react'; import { encode } from 'rison-node'; import url from 'url'; -import { stringify } from 'querystring'; import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'; import { TimeRange } from '../../../../common/http_api/shared/time_range'; import { url as urlUtils } from '../../../../../../../src/plugins/kibana_utils/public'; @@ -62,7 +61,7 @@ const getOverallAnomalyExplorerLink = (pathname: string, jobId: string, timeRang }, }); - const hash = `/explorer?${stringify(urlUtils.encodeQuery({ _g }))}`; + const hash = `/explorer?${urlUtils.makeUrlFromQuery({ _g })}`; return url.format({ pathname, @@ -95,7 +94,7 @@ const getPartitionSpecificSingleMetricViewerLink = ( }, }); - const hash = `/timeseriesexplorer?${stringify(urlUtils.encodeQuery({ _g, _a }))}`; + const hash = `/timeseriesexplorer?${urlUtils.makeUrlFromQuery({ _g, _a })}`; return url.format({ pathname, diff --git a/x-pack/plugins/infra/public/utils/url_state.tsx b/x-pack/plugins/infra/public/utils/url_state.tsx index ae3b834fa301d..5ccc6d3d11876 100644 --- a/x-pack/plugins/infra/public/utils/url_state.tsx +++ b/x-pack/plugins/infra/public/utils/url_state.tsx @@ -159,12 +159,10 @@ export const replaceStateKeyInQueryString = ( const encodedUrlState = typeof urlState !== 'undefined' ? encodeRisonUrlState(urlState) : undefined; - return stringify( - url.encodeQuery({ - ...previousQueryValues, - [stateKey]: encodedUrlState, - }) - ); + return url.makeUrlFromQuery({ + ...previousQueryValues, + [stateKey]: encodedUrlState, + }); }; const replaceQueryStringInLocation = (location: Location, queryString: string): Location => {