OpenLayers OpenLayers

Changeset 3284

Show
Ignore:
Timestamp:
06/07/07 14:32:10 (1 year ago)
Author:
crschmidt
Message:

OpenLayers.Util.getArgs returns wrong result with fragment identifiers, null
values in params, etc. From fredj. With tests! (Hooray for fredj)
Closes #734.

Files:

Legend:

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

    r3086 r3284  
    610610        url = window.location.href; 
    611611    } 
    612     var query = (url.indexOf('?') != -1) ? url.substring(url.indexOf('?') + 1)  
    613                                          : ''; 
    614      
     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         
    615626    var args = new Object(); 
    616627    pairs = query.split(/[&;]/); 
     
    619630        if(keyValue.length == 2) { 
    620631            args[decodeURIComponent(keyValue[0])] = 
    621                 decodeURIComponent(keyValue[1])
     632                decodeURIComponent(keyValue[1]) || ''
    622633        } 
    623634    } 
  • trunk/openlayers/tests/test_Util.html

    r2645 r3284  
    571571        t.eq(OpenLayers.Util.createDiv().id, "OpenLayersDiv3", "Div created is sequential, starting at lastSeqID in Util."); 
    572572    } 
     573 
     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    } 
     585 
    573586   // --> 
    574587  </script>