diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index d7582583b8..5ef3c612be 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -552,21 +552,32 @@ OpenLayers.Util.distVincenty=function(p1, p2) { var d = s.toFixed(3)/1000; // round to 1mm precision return d; }; - -OpenLayers.Util.getArgs = function() { - var args = new Object(); - var query = location.search.substring(1); // Get query string. - var pairs = query.split("&"); // Break at ampersand. //+pjl - for(var i = 0; i < pairs.length; i++) { - var pos = pairs[i].indexOf('='); // Look for "name=value". - if (pos == -1) continue; // If not found, skip. - var argname = pairs[i].substring(0,pos); // Extract the name. - var value = pairs[i].substring(pos+1); // Extract the value. - args[argname] = unescape(value); // Store as a property. +/** + * @param {String} url Optional url used to extract the query string. + * If null, query string is taken from page location. + * + * @returns An object of key/value pairs from the query string. + * @type Object + */ +OpenLayers.Util.getArgs = function(url) { + if(url == null) { + var query = window.location.search.substring(1); + } else { + var query = (url.indexOf('?') == -1) ? + '' : url.substring(url.indexOf('?') + 1); } - return args; // Return the object. -}; + 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]); + } + } + return args; +} /** * @param {String} prefix String to prefix random id. If null, default