OpenLayers OpenLayers

Changeset 7984

Show
Ignore:
Timestamp:
09/09/08 02:55:19 (3 months ago)
Author:
elemoine
Message:

Fix for "extra '?' is added to the URL by the LoadURL method", review and final patch from tschaub (closes #1616)

Files:

Legend:

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

    r7979 r7984  
    8888        var url = config.url; 
    8989        if(config.params) { 
    90             url += "?" + OpenLayers.Util.getParameterString(config.params); 
     90            var paramString = OpenLayers.Util.getParameterString(config.params); 
     91            if(paramString.length > 0) { 
     92                var separator = (url.indexOf('?') > -1) ? '&' : '?'; 
     93                url += separator + paramString; 
     94            } 
    9195        } 
    9296        if(config.proxy && (url.indexOf("http") == 0)) { 
  • trunk/openlayers/tests/Request.html

    r7609 r7984  
    2121        setup(); 
    2222 
    23         t.plan(19); 
     23        t.plan(22); 
    2424        var request, config; 
    2525        var proto = OpenLayers.Request.XMLHttpRequest.prototype; 
     
    4747            t.eq(user, config.user, "open called with correct user"); 
    4848            t.eq(password, config.password, "open called with correct password"); 
    49         } 
    50         request = issue(config); 
     49        }; 
     50        request = issue(config); 
     51         
     52        // test that params are serialized as query string - 1 test 
     53        config = { 
     54            method: "GET", 
     55            url: "http://example.com/", 
     56            params: {"foo": "bar"} 
     57        }; 
     58        proto.open = function(method, url, async, user, password) { 
     59            t.eq(url, config.url + "?foo=bar", "params serialized as query string"); 
     60        }; 
     61        request = issue(config); 
     62         
     63        // test that empty params object doesn't produce query string - 1 test 
     64        config = { 
     65            method: "GET", 
     66            url: "http://example.com/", 
     67            params: {} 
     68        }; 
     69        proto.open = function(method, url, async, user, password) { 
     70            t.eq(url, config.url, "empty params doesn't produce query string"); 
     71        } 
     72        request = issue(config); 
     73         
     74        // test that query string doesn't get two ? separators 
     75        config = { 
     76            method: "GET", 
     77            url: "http://example.com/?existing=query", 
     78            params: {"foo": "bar"} 
     79        }; 
     80        proto.open = function(method, url, async, user, password) { 
     81            t.eq(url, config.url + "&foo=bar", "existing query string gets extended with &"); 
     82        } 
     83        request = issue(config); 
     84 
     85        // reset open method 
    5186        proto.open = _open; 
    5287