OpenLayers OpenLayers

Changeset 3328

Show
Ignore:
Timestamp:
06/14/07 15:11:45 (1 year ago)
Author:
euzuro
Message:

2nd attempt fix for #734 -- tests pass in all browsers

Files:

Legend:

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

    r3325 r3328  
    610610        url = window.location.href; 
    611611    } 
    612     var query = (url.indexOf('?') != -1) ? url.substring(url.indexOf('?') + 1)  
    613                                          : ''; 
     612 
     613    var start = url.indexOf('?'); 
     614    var stop = url.indexOf('#'); 
     615     
     616    if (start != -1) { 
     617        if (stop != -1) { 
     618            var query = url.substring(start + 1, stop); 
     619        } else { 
     620            var query = url.substring(start + 1); 
     621        } 
     622    } else { 
     623        return {}; 
     624    } 
     625         
    614626    var args = new Object(); 
    615627    pairs = query.split(/[&;]/); 
    616628    for(var i = 0; i < pairs.length; ++i) { 
    617         keyValue = pairs[i].split(/=/); 
    618         if(keyValue.length == 2) { 
    619             args[decodeURIComponent(keyValue[0])] = 
    620                 decodeURIComponent(keyValue[1]); 
     629        keyValue = pairs[i].split('='); 
     630        if (keyValue[0]) { 
     631            if (keyValue[1]) {  
     632                args[decodeURIComponent(keyValue[0])] = decodeURIComponent(keyValue[1]); 
     633            } else { 
     634                args[decodeURIComponent(keyValue[0])] = ''; 
     635            } 
    621636        } 
    622637    } 
  • trunk/openlayers/tests/test_Util.html

    r3317 r3328  
    572572    } 
    573573 
     574    function test_Util_getArgs(t) { 
     575        t.plan(5); 
     576        t.eq(OpenLayers.Util.getArgs('http://www.example.com'), {}, "getArgs works when args = ''"); 
     577        t.eq(OpenLayers.Util.getArgs('http://www.example.com?'), {}, "getArgs works when args = '?'"); 
     578        t.eq(OpenLayers.Util.getArgs('http://www.example.com?hello=world&foo=bar'), 
     579                                     {'hello' : 'world', 'foo': 'bar'}, "getArgs works when args = '?hello=world&foo=bar'"); 
     580        t.eq(OpenLayers.Util.getArgs('http://www.example.com?hello=&foo=bar'), 
     581                                     {'hello' : '', 'foo': 'bar'}, "getArgs works when args = '?hello=&foo=bar'"); 
     582        t.eq(OpenLayers.Util.getArgs('http://www.example.com?foo=bar#bugssucks'), 
     583                                     {'foo': 'bar'}, "getArgs works when using a fragment identifier"); 
     584    } 
    574585   // --> 
    575586  </script>