Fix for "extra '?' is added to the URL by the LoadURL method", review and final patch from tschaub (closes #1616)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7984 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -87,7 +87,11 @@ OpenLayers.Request = {
|
||||
var request = new OpenLayers.Request.XMLHttpRequest();
|
||||
var url = config.url;
|
||||
if(config.params) {
|
||||
url += "?" + OpenLayers.Util.getParameterString(config.params);
|
||||
var paramString = OpenLayers.Util.getParameterString(config.params);
|
||||
if(paramString.length > 0) {
|
||||
var separator = (url.indexOf('?') > -1) ? '&' : '?';
|
||||
url += separator + paramString;
|
||||
}
|
||||
}
|
||||
if(config.proxy && (url.indexOf("http") == 0)) {
|
||||
url = config.proxy + encodeURIComponent(url);
|
||||
@@ -265,4 +269,4 @@ OpenLayers.Request = {
|
||||
return OpenLayers.Request.issue(config);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
function test_issue(t) {
|
||||
setup();
|
||||
|
||||
t.plan(19);
|
||||
t.plan(22);
|
||||
var request, config;
|
||||
var proto = OpenLayers.Request.XMLHttpRequest.prototype;
|
||||
var issue = OpenLayers.Function.bind(OpenLayers.Request.issue,
|
||||
@@ -46,8 +46,43 @@
|
||||
t.eq(async, config.async, "open called with correct async");
|
||||
t.eq(user, config.user, "open called with correct user");
|
||||
t.eq(password, config.password, "open called with correct password");
|
||||
};
|
||||
request = issue(config);
|
||||
|
||||
// test that params are serialized as query string - 1 test
|
||||
config = {
|
||||
method: "GET",
|
||||
url: "http://example.com/",
|
||||
params: {"foo": "bar"}
|
||||
};
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
t.eq(url, config.url + "?foo=bar", "params serialized as query string");
|
||||
};
|
||||
request = issue(config);
|
||||
|
||||
// test that empty params object doesn't produce query string - 1 test
|
||||
config = {
|
||||
method: "GET",
|
||||
url: "http://example.com/",
|
||||
params: {}
|
||||
};
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
t.eq(url, config.url, "empty params doesn't produce query string");
|
||||
}
|
||||
request = issue(config);
|
||||
|
||||
// test that query string doesn't get two ? separators
|
||||
config = {
|
||||
method: "GET",
|
||||
url: "http://example.com/?existing=query",
|
||||
params: {"foo": "bar"}
|
||||
};
|
||||
proto.open = function(method, url, async, user, password) {
|
||||
t.eq(url, config.url + "&foo=bar", "existing query string gets extended with &");
|
||||
}
|
||||
request = issue(config);
|
||||
|
||||
// reset open method
|
||||
proto.open = _open;
|
||||
|
||||
// test that headers are correctly set - 4 tests
|
||||
|
||||
Reference in New Issue
Block a user