diff --git a/public/js/icinga/util/async.js b/public/js/icinga/util/async.js index e1bf110ca..a696f1869 100644 --- a/public/js/icinga/util/async.js +++ b/public/js/icinga/util/async.js @@ -10,14 +10,18 @@ var pending = { }; - + + var encodeForURL = function(param) { + return encodeURIComponent(param); + }; + var getCurrentGETParameters = function() { var currentGET = window.location.search.substring(1).split("&"); var params = {}; if(currentGET.length > 0) { $.each(currentGET, function(idx, elem) { var keyVal = elem.split("="); - params[encodeURIComponent(keyVal[0])] = encodeURIComponent(keyVal[1]); + params[keyVal[0]] = encodeForURL(keyVal[1]); }); } return params; @@ -26,14 +30,17 @@ var pushGet = function(param, value, url) { url = url || (window.location.origin+window.location.pathname); var params = getCurrentGETParameters(); - params[encodeURIComponent(param)] = encodeURIComponent(value); + params[param] = encodeForURL(value); var search = "?"; for (var name in params) { - if(search != "?") + if (name === "" || typeof params[name] == "undefined") { + continue; + } + if (search != "?") search += "&"; search += name+"="+params[name]; } - + return url+search+"#"+window.location.hash; }; @@ -143,12 +150,11 @@ req.destination = destination; } if (destination == "icinga-main") { - History.pushState(data, document.title, url); + history.pushState(data, document.title, url); } else { url = pushGet("c["+destination+"]", url); - History.pushState(data, document.title, url); + history.pushState(data, document.title, url); } - console.log("New url: ", url); return req; }; diff --git a/public/js/main.js b/public/js/main.js index 0836be32c..cddc74127 100755 --- a/public/js/main.js +++ b/public/js/main.js @@ -10,13 +10,14 @@ requirejs.config({ "raphael.vml": 'vendor/raphael/raphael.vml', 'ace' : 'vendor/ace/ace', "Holder": 'vendor/holder', + "History": 'vendor/history', logging: 'icinga/util/logging' } }); -define(['jquery','Holder'], function ($) { +define(['jquery','Holder', 'History'], function ($) { requirejs(['bootstrap']); requirejs(['icinga/icinga'], function (Icinga) { window.$ = $; diff --git a/test/frontend/regression/regression-4408.js b/test/frontend/regression/regression-4408.js new file mode 100644 index 000000000..556928c94 --- /dev/null +++ b/test/frontend/regression/regression-4408.js @@ -0,0 +1,51 @@ +/** +* +* Regression test for #4408 +# History api double encodes and causes messy behaviour +* +**/ + +var i2w = require('./i2w-config'); +var casper = i2w.getTestEnv(); +var URL = "http://localhost:12999"; +var firstLink = "/fragments/testFragment1.html?c[test]=test_test"; +var secondLink = "/fragments/testFragment3.html?this=is_a_param"; +casper.start(URL+"/generic.html"); + + +casper.then(function() { + casper.page.evaluate(i2w.setupRequireJs, {icinga: true}); +}); + +casper.then(function() { + casper.page.evaluate(function() { + requirejs(["icinga/icinga"], function(icinga) { + icinga.loadUrl("/fragments/testFragment1.html?c[test]=test_test"); + }); + }); + casper.waitForSelector("div#icinga-main a", onFirstCall); + +}); + +/** +* First call of the loadUrl +**/ +var onFirstCall = function() { + this.test.assertUrlMatch(URL+firstLink); + casper.page.evaluate(function() { + requirejs(["icinga/icinga"], function(icinga) { + icinga.loadUrl("/fragments/testFragment3.html?this=is_a_param", "icinga-detail"); + }); + }); + this.wait(400, function() { + var expected = + URL + + firstLink+"&c[icinga-detail]=" + + secondLink; + this.test.assertUrlMatch(expected); + }); +}; + +casper.run(function() { + this.test.done(); +});