Commit 9421b827 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '337840-remove-urlparamstoobject-from-the-codebase' into 'master'

Remove deprecated "urlParamsToObject" function

See merge request gitlab-org/gitlab!68738
parents de498bc1 15c6aed0
......@@ -417,43 +417,6 @@ export const urlParamsToArray = (path = '') =>
export const getUrlParamsArray = () => urlParamsToArray(window.location.search);
/**
* Accepts encoding string which includes query params being
* sent to URL.
*
* @param {string} path Query param string
*
* @returns {object} Query params object containing key-value pairs
* with both key and values decoded into plain string.
*
* @deprecated Please use `queryToObject(query, { gatherArrays: true });` instead. See https://gitlab.com/gitlab-org/gitlab/-/issues/328845
*/
export const urlParamsToObject = (path = '') =>
splitPath(path).reduce((dataParam, filterParam) => {
if (filterParam === '') {
return dataParam;
}
const data = dataParam;
let [key, value] = filterParam.split('=');
key = /%\w+/g.test(key) ? decodeURIComponent(key) : key;
const isArray = key.includes('[]');
key = key.replace('[]', '');
value = decodeURIComponent(value.replace(/\+/g, ' '));
if (isArray) {
if (!data[key]) {
data[key] = [];
}
data[key].push(value);
} else {
data[key] = value;
}
return data;
}, {});
/**
* Convert search query into an object
*
......
......@@ -645,29 +645,6 @@ describe('URL utility', () => {
});
});
describe('urlParamsToObject', () => {
it('parses path for label with trailing +', () => {
// eslint-disable-next-line import/no-deprecated
expect(urlUtils.urlParamsToObject('label_name[]=label%2B', {})).toEqual({
label_name: ['label+'],
});
});
it('parses path for milestone with trailing +', () => {
// eslint-disable-next-line import/no-deprecated
expect(urlUtils.urlParamsToObject('milestone_title=A%2B', {})).toEqual({
milestone_title: 'A+',
});
});
it('parses path for search terms with spaces', () => {
// eslint-disable-next-line import/no-deprecated
expect(urlUtils.urlParamsToObject('search=two+words', {})).toEqual({
search: 'two words',
});
});
});
describe('queryToObject', () => {
it.each`
case | query | options | result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment