OpenLayers.Util.getArgs returns wrong result with fragment identifiers, null

values in params, etc. From fredj. With tests! (Hooray for fredj)
Closes #734.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@3284 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-06-07 18:32:10 +00:00
parent 29fa9361a8
commit 1c833a9b13
2 changed files with 27 additions and 3 deletions

View File

@@ -609,16 +609,27 @@ OpenLayers.Util.getArgs = function(url) {
if(url == null) {
url = window.location.href;
}
var query = (url.indexOf('?') != -1) ? url.substring(url.indexOf('?') + 1)
: '';
var start = url.indexOf('?');
var stop = url.indexOf('#');
if (start != -1) {
if (stop != -1) {
var query = url.substring(start + 1, stop);
} else {
var query = url.substring(start + 1);
}
} else {
return {};
}
var args = new Object();
pairs = query.split(/[&;]/);
for(var i = 0; i < pairs.length; ++i) {
keyValue = pairs[i].split(/=/);
if(keyValue.length == 2) {
args[decodeURIComponent(keyValue[0])] =
decodeURIComponent(keyValue[1]);
decodeURIComponent(keyValue[1]) || '';
}
}
return args;

View File

@@ -570,6 +570,19 @@
OpenLayers.Util.createDiv();
t.eq(OpenLayers.Util.createDiv().id, "OpenLayersDiv3", "Div created is sequential, starting at lastSeqID in Util.");
}
function test_Util_getArgs(t) {
t.plan(5);
t.eq(OpenLayers.Util.getArgs('http://www.example.com'), {}, "getArgs works when args = ''");
t.eq(OpenLayers.Util.getArgs('http://www.example.com?'), {}, "getArgs works when args = '?'");
t.eq(OpenLayers.Util.getArgs('http://www.example.com?hello=world&foo=bar'),
{'hello' : 'world', 'foo': 'bar'}, "getArgs works when args = '?hello=world&foo=bar'");
t.eq(OpenLayers.Util.getArgs('http://www.example.com?hello=&foo=bar'),
{'hello' : '', 'foo': 'bar'}, "getArgs works when args = '?hello=&foo=bar'");
t.eq(OpenLayers.Util.getArgs('http://www.example.com?foo=bar#bugssucks'),
{'foo': 'bar'}, "getArgs works when using a fragment identifier");
}
// -->
</script>
</head>