js: Properly parse/decode query params in `utils.parseParams()`

This commit is contained in:
Johannes Meyer 2019-11-20 13:50:00 +01:00
parent 4d790e70fc
commit 2dbf9ca8ab
2 changed files with 34 additions and 17 deletions

View File

@ -161,7 +161,7 @@
var keys = this.getMultiselectionKeys();
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (params[key]) {
if (params[key] || params[key] === null) {
tuple[key] = params[key];
}
}
@ -305,7 +305,12 @@
selections.each(function (i, el) {
var parts = [];
$.each(_this.getRowData($(el)), function(key, value) {
parts.push(utils.fixedEncodeURIComponent(key) + '=' + utils.fixedEncodeURIComponent(value));
var condition = utils.fixedEncodeURIComponent(key);
if (value !== null) {
condition += '=' + utils.fixedEncodeURIComponent(value);
}
parts.push(condition);
});
queries.push('(' + parts.join('&') + ')');
});

View File

@ -136,19 +136,25 @@
newparams[key] = value;
});
if (Object.keys(newparams).length > 0) {
var queryString = '?';
$.each(newparams, function (key, value) {
if (Object.keys(newparams).length) {
var queryString = '?';
$.each(newparams, function (key, value) {
if (queryString !== '?') {
queryString += '&';
}
queryString += encodeURIComponent(key) + '=' + encodeURIComponent(value);
});
result += queryString;
queryString += encodeURIComponent(key);
if (value !== null) {
queryString += '=' + encodeURIComponent(value);
}
});
result += queryString;
}
if (parts.hash.length > 0) {
if (parts.hash.length) {
result += '#' + parts.hash;
}
return result;
},
@ -162,19 +168,25 @@
delete newparams[key];
});
if (Object.keys(newparams).length > 0) {
var queryString = '?';
$.each(newparams, function (key, value) {
if (Object.keys(newparams).length) {
var queryString = '?';
$.each(newparams, function (key, value) {
if (queryString !== '?') {
queryString += '&';
}
queryString += encodeURIComponent(key) + '=' + encodeURIComponent(value);
});
result += queryString;
queryString += encodeURIComponent(key);
if (value !== null) {
queryString += '=' + encodeURIComponent(value);
}
});
result += queryString;
}
if (parts.hash.length > 0) {
if (parts.hash.length) {
result += '#' + parts.hash;
}
return result;
},
@ -193,7 +205,7 @@
continue;
}
s = segment[i].split('=');
params[s[0]] = decodeURIComponent(s[1]);
params[decodeURIComponent(s[0])] = typeof s[1] !== 'undefined' ? decodeURIComponent(s[1]) : null;
}
return params;
},