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:
Éric Lemoine
2008-09-09 06:55:19 +00:00
parent 30ab46f265
commit 4cf8b53027
2 changed files with 42 additions and 3 deletions

View File

@@ -87,7 +87,11 @@ OpenLayers.Request = {
var request = new OpenLayers.Request.XMLHttpRequest(); var request = new OpenLayers.Request.XMLHttpRequest();
var url = config.url; var url = config.url;
if(config.params) { 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)) { if(config.proxy && (url.indexOf("http") == 0)) {
url = config.proxy + encodeURIComponent(url); url = config.proxy + encodeURIComponent(url);

View File

@@ -20,7 +20,7 @@
function test_issue(t) { function test_issue(t) {
setup(); setup();
t.plan(19); t.plan(22);
var request, config; var request, config;
var proto = OpenLayers.Request.XMLHttpRequest.prototype; var proto = OpenLayers.Request.XMLHttpRequest.prototype;
var issue = OpenLayers.Function.bind(OpenLayers.Request.issue, var issue = OpenLayers.Function.bind(OpenLayers.Request.issue,
@@ -46,8 +46,43 @@
t.eq(async, config.async, "open called with correct async"); t.eq(async, config.async, "open called with correct async");
t.eq(user, config.user, "open called with correct user"); t.eq(user, config.user, "open called with correct user");
t.eq(password, config.password, "open called with correct password"); 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); 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; proto.open = _open;
// test that headers are correctly set - 4 tests // test that headers are correctly set - 4 tests