Merge branch 'bugfix/history-api-encoding-4408' into feature/host-overview--4179

This commit is contained in:
Jannis Moßhammer 2013-07-15 12:41:07 +02:00
commit bec7049785
3 changed files with 65 additions and 7 deletions

View File

@ -11,13 +11,17 @@
};
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,10 +30,13 @@
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];
}
@ -148,7 +155,6 @@
url = pushGet("c["+destination+"]", url);
history.pushState(data, document.title, url);
}
console.log("New url: ", url);
return req;
};

View File

@ -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.$ = $;

View File

@ -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();
});