Commit 2d376247 authored by Miguel Rincon's avatar Miguel Rincon

Disable legacySpacesDecode in urlQueryToFilter

This change passes the legacySpacesDecode parameter in the URL filters
to the urlQueryToFilter clients, so the function can reused without
using the legacy space parsing.
parent 9ee6c875
......@@ -43,7 +43,6 @@ export const fromUrlQueryToSearch = (query = window.location.search) => {
urlQueryToFilter(query, {
filterNamesAllowList: [PARAM_KEY_STATUS, PARAM_KEY_RUNNER_TYPE, PARAM_KEY_TAG],
filteredSearchTermKey: PARAM_KEY_SEARCH,
legacySpacesDecode: false,
}),
),
sort: params[PARAM_KEY_SORT] || DEFAULT_SORT,
......
......@@ -177,12 +177,13 @@ function filteredSearchTermValue(value) {
* @param {Object} options
* @param {String} [options.filteredSearchTermKey] if set, a FILTERED_SEARCH_TERM filter is created to this parameter. `'search'` is suggested
* @param {String[]} [options.filterNamesAllowList] if set, only this list of filters names is mapped
* @param {Boolean} [options.legacySpacesDecode] if set, plus symbols (+) are not encoded as spaces. `false` is suggested
* @param {Boolean} [options.legacySpacesDecode] if set to true, plus symbols (+) are not encoded as spaces.
* @return {Object} filter object with filter names and their values
*/
export function urlQueryToFilter(query = '', options = {}) {
const { filteredSearchTermKey, filterNamesAllowList, legacySpacesDecode = true } = options;
export function urlQueryToFilter(
query = '',
{ filteredSearchTermKey, filterNamesAllowList, legacySpacesDecode = false } = {},
) {
const filters = queryToObject(query, { gatherArrays: true, legacySpacesDecode });
return Object.keys(filters).reduce((memo, key) => {
const value = filters[key];
......
......@@ -20,7 +20,9 @@ export default () => {
labelsEndpoint: labelsPath,
projectEndpoint: projectPath,
});
const { milestone_title = null, label_name = [] } = urlQueryToFilter(window.location.search);
const { milestone_title = null, label_name = [] } = urlQueryToFilter(window.location.search, {
legacySpacesDecode: true,
});
store.dispatch('filters/initialize', {
selectedMilestone: milestone_title,
selectedLabelList: label_name,
......
......@@ -28,7 +28,9 @@ export default () => {
sort,
direction,
page,
} = urlQueryToFilter(window.location.search);
} = urlQueryToFilter(window.location.search, {
legacySpacesDecode: true,
});
store.dispatch('initializeCycleAnalytics', {
...initialData,
......
......@@ -35,7 +35,9 @@ export default () => {
author_username = null,
milestone_title = null,
label_name = [],
} = urlQueryToFilter(window.location.search);
} = urlQueryToFilter(window.location.search, {
legacySpacesDecode: true,
});
store.dispatch('filters/initialize', {
selectedSourceBranch: source_branch_name,
selectedTargetBranch: target_branch_name,
......
......@@ -309,7 +309,14 @@ describe('urlQueryToFilter', () => {
{
[FILTERED_SEARCH_TERM]: [{ value: 'my' }, { value: 'terms' }],
},
{ filteredSearchTermKey: 'search', legacySpacesDecode: false },
{ filteredSearchTermKey: 'search' },
],
[
'search=my+terms',
{
[FILTERED_SEARCH_TERM]: [{ value: 'my+terms' }],
},
{ filteredSearchTermKey: 'search', legacySpacesDecode: true },
],
[
'search=my terms&foo=bar&nop=xxx',
......
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