From 8abdd4f016bb057f8390f2473cf88497c10cf7d7 Mon Sep 17 00:00:00 2001 From: bartvde Date: Mon, 25 Jul 2011 14:01:00 +0000 Subject: [PATCH] modified checks for Format.WFST should use not equal to undefined instead of truthy to deal properly with initial null values, r=ahocevar (closes #3436) git-svn-id: http://svn.openlayers.org/trunk/openlayers@12188 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/WFST/v1.js | 12 ++++++------ tests/Format/WFST/v1.html | 10 +++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/Format/WFST/v1.js b/lib/OpenLayers/Format/WFST/v1.js index 8de0d6d368..2b5c04eb79 100644 --- a/lib/OpenLayers/Format/WFST/v1.js +++ b/lib/OpenLayers/Format/WFST/v1.js @@ -183,12 +183,12 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { * transaction: * - *modified* is not set at all: The geometry and all attributes will be * included. - * - *modified.geometry* is truthy: The geometry will be + * - *modified.geometry* is set (null or a geometry): The geometry will be * included. If *modified.attributes* is not set, all attributes will * be included. - * - *modified.attributes* is set: Only the attributes with a truthy value - * in *modified.attributes* will be included. If *modified.geometry* - * is not set, the geometry will not be included. + * - *modified.attributes* is set: Only the attributes set (i.e. to null or + * a value) in *modified.attributes* will be included. + * If *modified.geometry* is not set, the geometry will not be included. * * Valid options include: * - *multi* {Boolean} If set to true, geometries will be casted to @@ -323,7 +323,7 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { // add in geometry var modified = feature.modified; - if (this.geometryName !== null && (!modified || modified.geometry)) { + if (this.geometryName !== null && (!modified || modified.geometry !== undefined)) { this.srsName = this.getSrsName(feature); this.writeNode( "Property", {name: this.geometryName, value: feature.geometry}, node @@ -334,7 +334,7 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { for(var key in feature.attributes) { if(feature.attributes[key] !== undefined && (!modified || !modified.attributes || - (modified.attributes && modified.attributes[key]))) { + (modified.attributes && modified.attributes[key] !== undefined))) { this.writeNode( "Property", {name: key, value: feature.attributes[key]}, node ); diff --git a/tests/Format/WFST/v1.html b/tests/Format/WFST/v1.html index cce58f815e..04142b60e0 100644 --- a/tests/Format/WFST/v1.html +++ b/tests/Format/WFST/v1.html @@ -45,7 +45,7 @@ deleteFeature.state = OpenLayers.State.DELETE; deleteFeature.fid = "fid.37"; - t.plan(7); + t.plan(8); var snippets = { "GetFeature": {handle: "handle_g", maxFeatures: 1, outputFormat: 'json'}, "Transaction": {handle: "handle_t"}, @@ -74,6 +74,14 @@ var expected = readXML("UpdateModifiedNoGeometry"); var got = format.writers["wfs"]["Update"].apply(format, [{feature: updateFeature}]); t.xml_eq(got, expected, "Update request for feature with no modified geometry but modified attributes created correctly"); + + // test for a feature that originally had a null geometry and a null value for the attribute + updateFeature.modified = {attributes: {foo: null, nul: "nul"}, geometry: null}; + updateFeature.attributes.foo = "bar"; + updateFeature.geometry = new OpenLayers.Geometry.Point(2,3); + var expected = readXML("UpdateModified"); + var got = format.writers["wfs"]["Update"].apply(format, [{feature: updateFeature}]); + t.xml_eq(got, expected, "Update request for feature with modified geometry created correctly even if original geometry was null"); } function test_writeNative(t) {