From 4d02d8f6d6bc38dacd9bea4409d6d184c292b602 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 14 Jan 2020 14:53:08 +0100 Subject: [PATCH 1/4] JS: Introduce Icinga.Utils.addUrlFlag() --- public/js/icinga/utils.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/public/js/icinga/utils.js b/public/js/icinga/utils.js index 8b2a90921..615e3ab0f 100644 --- a/public/js/icinga/utils.js +++ b/public/js/icinga/utils.js @@ -210,6 +210,30 @@ return params; }, + /** + * Add the specified flag to the given URL + * + * @param {string} url + * @param {string} flag + * + * @returns {string} + */ + addUrlFlag: function (url, flag) { + var pos = url.lastIndexOf('#'); + + if (url.indexOf('?') !== -1) { + flag = '&' + flag; + } else { + flag = '?' + flag; + } + + if (pos === -1) { + return url + flag; + } + + return url.slice(0, pos) + flag + url.slice(pos); + }, + /** * Check whether two HTMLElements overlap * From 7f8ee4f94dce38d105786acc7bfbe51215bebf48 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 14 Jan 2020 14:53:25 +0100 Subject: [PATCH 2/4] JS: Deprecate Icinga.Loader.addUrlFlag() in favor of Icinga.Utils.addUrlFlag() --- public/js/icinga/loader.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index e1dea3e1d..36fd72ec3 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -415,13 +415,19 @@ return true; }, + /** + * Add the specified flag to the given URL + * + * @param {string} url + * @param {string} flag + * + * @returns {string} + * + * @deprecated since version 2.8.0. Use {@link Icinga.Utils.addUrlFlag()} instead + */ addUrlFlag: function(url, flag) { - if (url.match(/\?/)) { - return url + '&' + flag; - } else { - return url + '?' + flag; - } + return this.icinga.utils.addUrlFlag(url, flag); }, /** From e45c18c833f16a0137051793c34737512c4ac955 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 15 Jan 2020 07:58:49 +0100 Subject: [PATCH 3/4] utils.js: Use a regex to identify the uri fragment --- public/js/icinga/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/icinga/utils.js b/public/js/icinga/utils.js index 615e3ab0f..07250c6b6 100644 --- a/public/js/icinga/utils.js +++ b/public/js/icinga/utils.js @@ -219,7 +219,7 @@ * @returns {string} */ addUrlFlag: function (url, flag) { - var pos = url.lastIndexOf('#'); + var pos = url.search(/#(?!!)/); if (url.indexOf('?') !== -1) { flag = '&' + flag; From 844cb911a400ce59c7ae8b2aeee878d5f1274d92 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 15 Jan 2020 08:00:04 +0100 Subject: [PATCH 4/4] loader.js: Use `utils.addUrlFlag` instead of the now deprecated one --- public/js/icinga/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 36fd72ec3..6b6ddb81a 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -549,7 +549,7 @@ if (rerenderLayout) { var parts = url.split(/#!/); url = parts.shift(); - var redirectionUrl = this.addUrlFlag(url, 'renderLayout'); + var redirectionUrl = icinga.utils.addUrlFlag(url, 'renderLayout'); var r = this.loadUrl(redirectionUrl, $('#layout')); r.historyUrl = url; if (parts.length) {