fixed getParameterString to handle null/undefined values correctly. r=elemoine (closes #2157)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9573 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -608,8 +608,12 @@ OpenLayers.Util.getParameterString = function(params) {
|
|||||||
if (typeof value == 'object' && value.constructor == Array) {
|
if (typeof value == 'object' && value.constructor == Array) {
|
||||||
/* value is an array; encode items and separate with "," */
|
/* value is an array; encode items and separate with "," */
|
||||||
var encodedItemArray = [];
|
var encodedItemArray = [];
|
||||||
|
var item;
|
||||||
for (var itemIndex=0, len=value.length; itemIndex<len; itemIndex++) {
|
for (var itemIndex=0, len=value.length; itemIndex<len; itemIndex++) {
|
||||||
encodedItemArray.push(encodeURIComponent(value[itemIndex]));
|
item = value[itemIndex];
|
||||||
|
encodedItemArray.push(encodeURIComponent(
|
||||||
|
(item === null || item === undefined) ? "" : item)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
encodedValue = encodedItemArray.join(",");
|
encodedValue = encodedItemArray.join(",");
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -225,7 +225,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Util_getParameterString(t) {
|
function test_Util_getParameterString(t) {
|
||||||
t.plan( 4 );
|
t.plan( 5 );
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
'foo': "bar",
|
'foo': "bar",
|
||||||
@@ -242,7 +242,10 @@
|
|||||||
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar%2Cbaz", "getParameterString encodes , correctly in arrays");
|
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar%2Cbaz", "getParameterString encodes , correctly in arrays");
|
||||||
|
|
||||||
var params = { foo: ["bar","baz,"] };
|
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. ");
|
t.eq( OpenLayers.Util.getParameterString(params), "foo=bar,baz%2C", "getParameterString returns with list of CSVs when given a list. ");
|
||||||
|
|
||||||
|
var params = { foo: [null, undefined, 0, "", "bar"] }
|
||||||
|
t.eq( OpenLayers.Util.getParameterString(params), "foo=,,0,,bar", "getParameterString works fine with null values in array.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Util_createAlphaImageDiv(t) {
|
function test_Util_createAlphaImageDiv(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user