OpenLayers OpenLayers

Changeset 2232

Show
Ignore:
Timestamp:
02/16/07 14:38:00 (2 years ago)
Author:
crschmidt
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Util.js

    r2231 r2232  
    395395*    http parameter notation.  
    396396*    (ex. <i>"key1=value1&key2=value2&key3=value3"</i>) 
     397*    If a parameter is actually a list, that parameter will then 
     398*    be set to a comma-seperated list of values (foo,bar) instead 
     399*    of being URL escaped (foo%3Abar).  
    397400* @type String 
    398401*/ 
     
    401404     
    402405    for (var key in params) { 
    403         var value = params[key]; 
    404         if ((value != null) && (typeof value != 'function')) { 
    405             paramsArray.push(encodeURIComponent(key) + "=" + 
    406                              encodeURIComponent(value)); 
    407         } 
     406      var value = params[key]; 
     407      if ((value != null) && (typeof value != 'function')) { 
     408        var encodedValue; 
     409        if (typeof value == 'object' && value.constructor == Array) { 
     410          /* value is an array; encode items and separate with "," */ 
     411          var encodedItemArray = new Array(); 
     412          for (var itemIndex=0; itemIndex<value.length; itemIndex++) { 
     413            encodedItemArray.push(encodeURIComponent(value[itemIndex])); 
     414          } 
     415          encodedValue = encodedItemArray.join(","); 
     416        } 
     417        else { 
     418          /* value is a string; simply encode */ 
     419          encodedValue = encodeURIComponent(value); 
     420        } 
     421        paramsArray.push(encodeURIComponent(key) + "=" + encodedValue); 
     422      } 
    408423    } 
    409424     
  • trunk/openlayers/tests/test_Util.html

    r2162 r2232  
    178178 
    179179    function test_07_Util_getParameterString(t) { 
    180         t.plan( 2 ); 
     180        t.plan( 4 ); 
    181181 
    182182        var params = { foo: "bar", 
     
    186186        t.eq( OpenLayers.Util.getParameterString(params), "foo=bar&chicken=1.5", "getParameterString returns correctly");     
    187187        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. ");     
    188197    } 
    189198