Change the encoding of parameters, as discussed in #491. The reason this

is important is that the WMS spec specifies that you should seperate layer
names with a ",", and we were encoding that, so compliant WMSes would attempt
to find a single layer with ","s in the name, instead of grabbing multiple
layers. The new way to specify multiple layers is to set:
  layers: ['global_modis','landsat'] 
or the like.
Includes tests, signoff from SDE.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@2232 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-02-16 20:38:00 +00:00
parent 3309b0b12e
commit 1d06490b2c
2 changed files with 29 additions and 5 deletions

View File

@@ -394,17 +394,32 @@ OpenLayers.Util.applyDefaults = function (to, from) {
* @returns a concatenation of the properties of an object in * @returns a concatenation of the properties of an object in
* http parameter notation. * http parameter notation.
* (ex. <i>"key1=value1&key2=value2&key3=value3"</i>) * (ex. <i>"key1=value1&key2=value2&key3=value3"</i>)
* If a parameter is actually a list, that parameter will then
* be set to a comma-seperated list of values (foo,bar) instead
* of being URL escaped (foo%3Abar).
* @type String * @type String
*/ */
OpenLayers.Util.getParameterString = function(params) { OpenLayers.Util.getParameterString = function(params) {
paramsArray = new Array(); paramsArray = new Array();
for (var key in params) { for (var key in params) {
var value = params[key]; var value = params[key];
if ((value != null) && (typeof value != 'function')) { if ((value != null) && (typeof value != 'function')) {
paramsArray.push(encodeURIComponent(key) + "=" + var encodedValue;
encodeURIComponent(value)); if (typeof value == 'object' && value.constructor == Array) {
/* value is an array; encode items and separate with "," */
var encodedItemArray = new Array();
for (var itemIndex=0; itemIndex<value.length; itemIndex++) {
encodedItemArray.push(encodeURIComponent(value[itemIndex]));
}
encodedValue = encodedItemArray.join(",");
} }
else {
/* value is a string; simply encode */
encodedValue = encodeURIComponent(value);
}
paramsArray.push(encodeURIComponent(key) + "=" + encodedValue);
}
} }
return paramsArray.join("&"); return paramsArray.join("&");

View File

@@ -177,7 +177,7 @@
} }
function test_07_Util_getParameterString(t) { function test_07_Util_getParameterString(t) {
t.plan( 2 ); t.plan( 4 );
var params = { foo: "bar", var params = { foo: "bar",
chicken: 1.5 chicken: 1.5
@@ -185,6 +185,15 @@
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly"); t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly");
t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values"); t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values");
// Parameters which are a list should end up being a comma-seperated
// list of the URL encoded strings
var params = { foo: ["bar,baz"] };
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar%2Cbaz", "getParameterString encodes , correctly in arrays");
var params = { foo: ["bar","baz,"] };
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar,baz%2C", "getParameterString returns with list of CSVs when given a list. ");
} }
function test_08_Util_createAlphaImageDiv(t) { function test_08_Util_createAlphaImageDiv(t) {