Fix history api URI encoding
The history API encoded components multiple times, e.g. causing a [ to be converted to %5B in the first link, then to %255B on the second link, %25255B on the third, etc. refs #4408
This commit is contained in:
parent
a035473914
commit
673f73b38a
|
@ -11,13 +11,17 @@
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var encodeForURL = function(param) {
|
||||||
|
return encodeURIComponent(param);
|
||||||
|
};
|
||||||
|
|
||||||
var getCurrentGETParameters = function() {
|
var getCurrentGETParameters = function() {
|
||||||
var currentGET = window.location.search.substring(1).split("&");
|
var currentGET = window.location.search.substring(1).split("&");
|
||||||
var params = {};
|
var params = {};
|
||||||
if(currentGET.length > 0) {
|
if(currentGET.length > 0) {
|
||||||
$.each(currentGET, function(idx, elem) {
|
$.each(currentGET, function(idx, elem) {
|
||||||
var keyVal = elem.split("=");
|
var keyVal = elem.split("=");
|
||||||
params[encodeURIComponent(keyVal[0])] = encodeURIComponent(keyVal[1]);
|
params[keyVal[0]] = encodeForURL(keyVal[1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
|
@ -26,10 +30,13 @@
|
||||||
var pushGet = function(param, value, url) {
|
var pushGet = function(param, value, url) {
|
||||||
url = url || (window.location.origin+window.location.pathname);
|
url = url || (window.location.origin+window.location.pathname);
|
||||||
var params = getCurrentGETParameters();
|
var params = getCurrentGETParameters();
|
||||||
params[encodeURIComponent(param)] = encodeURIComponent(value);
|
params[param] = encodeForURL(value);
|
||||||
var search = "?";
|
var search = "?";
|
||||||
for (var name in params) {
|
for (var name in params) {
|
||||||
if(search != "?")
|
if (name === "" || typeof params[name] == "undefined") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (search != "?")
|
||||||
search += "&";
|
search += "&";
|
||||||
search += name+"="+params[name];
|
search += name+"="+params[name];
|
||||||
}
|
}
|
||||||
|
@ -143,12 +150,11 @@
|
||||||
req.destination = destination;
|
req.destination = destination;
|
||||||
}
|
}
|
||||||
if (destination == "icinga-main") {
|
if (destination == "icinga-main") {
|
||||||
History.pushState(data, document.title, url);
|
history.pushState(data, document.title, url);
|
||||||
} else {
|
} else {
|
||||||
url = pushGet("c["+destination+"]", url);
|
url = pushGet("c["+destination+"]", url);
|
||||||
History.pushState(data, document.title, url);
|
history.pushState(data, document.title, url);
|
||||||
}
|
}
|
||||||
console.log("New url: ", url);
|
|
||||||
return req;
|
return req;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,14 @@ requirejs.config({
|
||||||
"raphael.vml": 'vendor/raphael/raphael.vml',
|
"raphael.vml": 'vendor/raphael/raphael.vml',
|
||||||
'ace' : 'vendor/ace/ace',
|
'ace' : 'vendor/ace/ace',
|
||||||
"Holder": 'vendor/holder',
|
"Holder": 'vendor/holder',
|
||||||
|
"History": 'vendor/history',
|
||||||
|
|
||||||
logging: 'icinga/util/logging'
|
logging: 'icinga/util/logging'
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
define(['jquery','Holder'], function ($) {
|
define(['jquery','Holder', 'History'], function ($) {
|
||||||
requirejs(['bootstrap']);
|
requirejs(['bootstrap']);
|
||||||
requirejs(['icinga/icinga'], function (Icinga) {
|
requirejs(['icinga/icinga'], function (Icinga) {
|
||||||
window.$ = $;
|
window.$ = $;
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
Loading…
Reference in New Issue