diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index e2aaddfa0a..c297b4d472 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -563,7 +563,7 @@ OpenLayers.Util.applyDefaults = function (to, from) { * properties with the for(property in object) syntax. Explicitly check if * the source has its own toString property. */ - if(!fromIsEvt && from.hasOwnProperty + if(!fromIsEvt && from && from.hasOwnProperty && from.hasOwnProperty('toString') && !to.hasOwnProperty('toString')) { to.toString = from.toString; } diff --git a/tests/Util.html b/tests/Util.html index 624b19df43..56263a1782 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -169,7 +169,7 @@ function test_Util_applyDefaults(t) { - t.plan(11); + t.plan(12); var to = { 'a': "abra", @@ -204,6 +204,15 @@ var ret = OpenLayers.Util.applyDefaults(to, from); t.eq(ret.rand, from.rand, "works with undefined to"); + + //regression test for #1716 -- allow undefined from + try { + OpenLayers.Util.applyDefaults({}, undefined); + t.ok(true, "no exception thrown when from is undefined"); + } catch(err) { + t.fail("exception thrown when from is undefined:" + err); + } + } function test_Util_getParameterString(t) {