diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index 59ca6c2401..6a72d2bb75 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -125,14 +125,8 @@ OpenLayers.Request = { // create request, open, and set headers var request = new OpenLayers.Request.XMLHttpRequest(); - var url = config.url; - if(config.params) { - var paramString = OpenLayers.Util.getParameterString(config.params); - if(paramString.length > 0) { - var separator = (url.indexOf('?') > -1) ? '&' : '?'; - url += separator + paramString; - } - } + var url = OpenLayers.Util.urlAppend(config.url, + OpenLayers.Util.getParameterString(config.params)); var sameOrigin = !(url.indexOf("http") == 0); var urlParts = !sameOrigin && url.match(this.URL_SPLIT_REGEX); if (urlParts) { diff --git a/tests/Request.html b/tests/Request.html index 20e7a7579f..f4db5fdcfe 100644 --- a/tests/Request.html +++ b/tests/Request.html @@ -20,7 +20,7 @@ function test_issue(t) { setup(); - t.plan(21); + t.plan(22); var request, config; var proto = OpenLayers.Request.XMLHttpRequest.prototype; var issue = OpenLayers.Function.bind(OpenLayers.Request.issue, @@ -81,7 +81,18 @@ t.eq(url, config.url + "&foo=bar", "existing query string gets extended with &"); } request = issue(config); - + + // test that query string doesn't get ? followed by & + config = { + method: "GET", + url: "http://example.com/service?", + params: {"foo": "bar"} + }; + proto.open = function(method, url, async, user, password) { + t.eq(url, config.url + "foo=bar", "existing query string ending with ? gets extended without &"); + } + request = issue(config); + // reset open method proto.open = _open;