From 2dbf9ca8ab3a5fcef1ce3a54d7c3b1c8ae617875 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 20 Nov 2019 13:50:00 +0100 Subject: [PATCH] js: Properly parse/decode query params in `utils.parseParams()` --- public/js/icinga/behavior/actiontable.js | 9 +++-- public/js/icinga/utils.js | 42 +++++++++++++++--------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/public/js/icinga/behavior/actiontable.js b/public/js/icinga/behavior/actiontable.js index 579018db8..a9e587f9d 100644 --- a/public/js/icinga/behavior/actiontable.js +++ b/public/js/icinga/behavior/actiontable.js @@ -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('&') + ')'); }); diff --git a/public/js/icinga/utils.js b/public/js/icinga/utils.js index 4d979dbcf..34caab3ca 100644 --- a/public/js/icinga/utils.js +++ b/public/js/icinga/utils.js @@ -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; },