Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/lib/utils/url_utility.js')
-rw-r--r--app/assets/javascripts/lib/utils/url_utility.js38
1 files changed, 24 insertions, 14 deletions
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
index 5b3aa3cf9dc..48abc072675 100644
--- a/app/assets/javascripts/lib/utils/url_utility.js
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -323,7 +323,7 @@ export function isAbsolute(url) {
* @param {String} url
*/
export function isRootRelative(url) {
- return /^\//.test(url);
+ return /^\/(?!\/)/.test(url);
}
/**
@@ -414,29 +414,35 @@ export function getWebSocketUrl(path) {
*
* @param {String} query from "document.location.search"
* @param {Object} options
- * @param {Boolean} options.gatherArrays - gather array values into an Array
+ * @param {Boolean?} options.gatherArrays - gather array values into an Array
+ * @param {Boolean?} options.legacySpacesDecode - (deprecated) plus symbols (+) are not replaced with spaces, false by default
* @returns {Object}
*
* ex: "?one=1&two=2" into {one: 1, two: 2}
*/
-export function queryToObject(query, options = {}) {
- const { gatherArrays = false } = options;
+export function queryToObject(query, { gatherArrays = false, legacySpacesDecode = false } = {}) {
const removeQuestionMarkFromQuery = String(query).startsWith('?') ? query.slice(1) : query;
return removeQuestionMarkFromQuery.split('&').reduce((accumulator, curr) => {
const [key, value] = curr.split('=');
if (value === undefined) {
return accumulator;
}
- const decodedValue = decodeURIComponent(value);
+
+ const decodedValue = legacySpacesDecode ? decodeURIComponent(value) : decodeUrlParameter(value);
if (gatherArrays && key.endsWith('[]')) {
- const decodedKey = decodeURIComponent(key.slice(0, -2));
+ const decodedKey = legacySpacesDecode
+ ? decodeURIComponent(key.slice(0, -2))
+ : decodeUrlParameter(key.slice(0, -2));
+
if (!Array.isArray(accumulator[decodedKey])) {
accumulator[decodedKey] = [];
}
accumulator[decodedKey].push(decodedValue);
} else {
- accumulator[decodeURIComponent(key)] = decodedValue;
+ const decodedKey = legacySpacesDecode ? decodeURIComponent(key) : decodeUrlParameter(key);
+
+ accumulator[decodedKey] = decodedValue;
}
return accumulator;
@@ -484,13 +490,17 @@ export const setUrlParams = (
searchParams.delete(key);
} else if (Array.isArray(params[key])) {
const keyName = railsArraySyntax ? `${key}[]` : key;
- params[key].forEach((val, idx) => {
- if (idx === 0) {
- searchParams.set(keyName, val);
- } else {
- searchParams.append(keyName, val);
- }
- });
+ if (params[key].length === 0) {
+ searchParams.delete(keyName);
+ } else {
+ params[key].forEach((val, idx) => {
+ if (idx === 0) {
+ searchParams.set(keyName, val);
+ } else {
+ searchParams.append(keyName, val);
+ }
+ });
+ }
} else {
searchParams.set(key, params[key]);
}