diff --git a/lib/OpenLayers/BaseTypes/Class.js b/lib/OpenLayers/BaseTypes/Class.js index 81316236af..d9f1ad5551 100644 --- a/lib/OpenLayers/BaseTypes/Class.js +++ b/lib/OpenLayers/BaseTypes/Class.js @@ -40,15 +40,21 @@ OpenLayers.Class = function() { if(typeof arguments[i] == "function") { // make the class passed as the first argument the superclass if(i == 0 && len > 1) { - // replace the initialize method with an empty function, - // because we do not want to create a real instance here initialize = arguments[i].prototype.initialize; - arguments[i].prototype.initialize = function() {}; - // the line below makes sure that the new class has a - // superclass - extended = new arguments[i]; - // restore the original initialize method - arguments[i].prototype.initialize = initialize; + if(typeof initialize === "function") { + // replace the initialize method with an empty function, + // because we do not want to create a real instance here + arguments[i].prototype.initialize = function() {}; + // the line below makes sure that the new class has a + // superclass + extended = new arguments[i]; + // restore the original initialize method + arguments[i].prototype.initialize = initialize; + } else { + // if someone uses Class to mix objects, we don't want to + // mess with the prototype + extended = new arguments[i]; + } } // get the prototype of the superclass parent = arguments[i].prototype; diff --git a/lib/OpenLayers/Format/GML.js b/lib/OpenLayers/Format/GML.js index de7b16dd9a..d6ba5d409a 100644 --- a/lib/OpenLayers/Format/GML.js +++ b/lib/OpenLayers/Format/GML.js @@ -558,6 +558,12 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, { this.regExes.trimSpace, ""); attributes[name] = value; } + } else { + // If child has no childNodes (grandchildren), + // set an attribute with null value. + // e.g. becomes + // {fieldname: null} + attributes[child.nodeName.split(":").pop()] = null; } } } diff --git a/tests/BaseTypes/Class.html b/tests/BaseTypes/Class.html index 47aea9fbc4..ccb155ca6f 100644 --- a/tests/BaseTypes/Class.html +++ b/tests/BaseTypes/Class.html @@ -51,7 +51,7 @@ } function test_Class_inheritance(t) { - t.plan(4); + t.plan(5); var BaseClass = OpenLayers.Class({ prop: "base", @@ -81,6 +81,10 @@ t.eq(child["CLASS_NAME"], "ChildClass", "new object is an instance of the child class"); + + var F = OpenLayers.Class(Object, {}); + t.ok(!("initialize" in Object.prototype), "no messing with non OL prototypes"); + } function test_Class_multiple_inheritance(t) { diff --git a/tests/Format/GML.html b/tests/Format/GML.html index 3548a5b0ee..1352eb2541 100644 --- a/tests/Format/GML.html +++ b/tests/Format/GML.html @@ -153,11 +153,12 @@ t.eq(data[0].geometry.components.length, 2, "rings length correct"); } function test_Format_GML_read_attributes(t) { - t.plan(2); + t.plan(3); var parser = new OpenLayers.Format.GML(); data = parser.read(test_content[0]); t.eq(data[0].attributes['NAME'], "WY", "Simple Attribute data is read correctly."); t.eq(data[0].attributes['LONGNAME'], "Wyoming", "Attribute data is read from CDATA node correctly."); + t.ok(data[0].attributes['EMPTYATTR'] === null, "Attribute set to null for empty element."); } function test_Format_GML_read_envelope_geom(t) { t.plan(13); @@ -338,7 +339,7 @@ t.xml_eq(output, expect, "[xy true] Bounds correctly written as gml:Box"); } - var test_content = ['\n\n \n \n -1254041.389711702250906.9515983529\n -634517.1199908922762236.2940800377\n \n \n \n \n -634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0\n WY\n \n \n \n\n', + var test_content = ['\n\n \n \n -1254041.389711702250906.9515983529\n -634517.1199908922762236.2940800377\n \n \n \n \n -634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0\n WY\n \n \n \n\n', '