From 533f8625d98e1700ba16899a7df8b7f3204961e1 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Mon, 8 Aug 2011 13:43:14 +0000 Subject: [PATCH] Thanks to a patch from greid, fix case where "" is passed into getParameters, which would previously have weird behavior. (Pullup #3408) git-svn-id: http://svn.openlayers.org/trunk/openlayers@12217 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 5 +++-- tests/Util.html | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index a455e77948..6d7681bf9b 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -943,14 +943,15 @@ OpenLayers.Util.destinationVincenty = function(lonlat, brng, dist) { * * Parameters: * url - {String} Optional url used to extract the query string. - * If null, query string is taken from page location. + * If url is null or is not supplied, query string is taken + * from the page location. * * Returns: * {Object} An object of key/value pairs from the query string. */ OpenLayers.Util.getParameters = function(url) { // if no url specified, take it from the location bar - url = url || window.location.href; + url = (url === null || url === undefined) ? window.location.href : url; //parse out parameters portion of url string var paramsString = ""; diff --git a/tests/Util.html b/tests/Util.html index e1476041aa..f70cbb9ddf 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -952,7 +952,16 @@ } function test_Util_getParameters(t) { - t.plan(17); + t.plan(20); + + t.eq(OpenLayers.Util.getParameters(''), {}, + "getParameters works when the given argument is empty string"); + + t.eq(OpenLayers.Util.getParameters(), {}, + "getParameters works with optional argument"); + + t.eq(OpenLayers.Util.getParameters(null), {}, + "getParameters works with optional argument"); t.eq(OpenLayers.Util.getParameters('http://www.example.com'), {}, "getParameters works when args = ''");