Ticket #491: 491.2.patch
| File 491.2.patch, 2.9 kB (added by crschmidt, 2 years ago) |
|---|
-
tests/test_Util.html
old new 177 177 } 178 178 179 179 function test_07_Util_getParameterString(t) { 180 t.plan( 2);180 t.plan( 4 ); 181 181 182 182 var params = { foo: "bar", 183 183 chicken: 1.5 … … 185 185 186 186 t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly"); 187 187 t.eq( OpenLayers.Util.getParameterString({'a:':'b='}), "a%3A=b%3D", "getParameterString returns correctly with non-ascii keys/values"); 188 189 190 // Parameters which are a list should end up being a comma-seperated 191 // list of the URL encoded strings 192 var params = { foo: ["bar,baz"] }; 193 t.eq( OpenLayers.Util.getParameterString(params), "foo=bar%2Cbaz", "getParameterString encodes , correctly in arrays"); 194 195 var params = { foo: ["bar","baz,"] }; 196 t.eq( OpenLayers.Util.getParameterString(params), "foo=bar,baz%2C", "getParameterString returns with list of CSVs when given a list. "); 188 197 } 189 198 190 199 function test_08_Util_createAlphaImageDiv(t) { -
lib/OpenLayers/Util.js
old new 377 387 * @returns a concatenation of the properties of an object in 378 388 * http parameter notation. 379 389 * (ex. <i>"key1=value1&key2=value2&key3=value3"</i>) 390 * If a parameter is actually a list, that parameter will then 391 * be set to a comma-seperated list of values (foo,bar) instead 392 * of being URL escaped (foo%3Abar). 380 393 * @type String 381 394 */ 382 395 OpenLayers.Util.getParameterString = function(params) { 383 396 paramsArray = new Array(); 384 397 385 398 for (var key in params) { 386 var value = params[key]; 387 if ((value != null) && (typeof value != 'function')) { 388 paramsArray.push(encodeURIComponent(key) + "=" + 389 encodeURIComponent(value)); 399 var value = params[key]; 400 if ((value != null) && (typeof value != 'function')) { 401 var encodedValue; 402 if (typeof value == 'object' && value.constructor == Array) { 403 /* value is an array; encode items and separate with "," */ 404 var encodedItemArray = new Array(); 405 for (var itemIndex=0; itemIndex<value.length; itemIndex++) { 406 encodedItemArray.push(encodeURIComponent(value[itemIndex])); 407 } 408 encodedValue = encodedItemArray.join(","); 390 409 } 410 else { 411 /* value is a string; simply encode */ 412 encodedValue = encodeURIComponent(value); 413 } 414 paramsArray.push(encodeURIComponent(key) + "=" + encodedValue); 415 } 391 416 } 392 417 393 418 return paramsArray.join("&");
