diff --git a/lib/OpenLayers/Format/WMSGetFeatureInfo.js b/lib/OpenLayers/Format/WMSGetFeatureInfo.js index 6277b98536..52b1223fc9 100644 --- a/lib/OpenLayers/Format/WMSGetFeatureInfo.js +++ b/lib/OpenLayers/Format/WMSGetFeatureInfo.js @@ -230,12 +230,14 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { var child = children[i]; if (child.nodeType == 1) { var grandchildren = child.childNodes; - if (grandchildren.length == 1) { + var name = (child.prefix) ? + child.nodeName.split(":")[1] : child.nodeName; + if (grandchildren.length == 0) { + attributes[name] = null + } else if (grandchildren.length == 1) { var grandchild = grandchildren[0]; if (grandchild.nodeType == 3 || grandchild.nodeType == 4) { - var name = (child.prefix) ? - child.nodeName.split(":")[1] : child.nodeName; var value = grandchild.nodeValue.replace( this.regExes.trimSpace, ""); attributes[name] = value; diff --git a/tests/Format/WMSGetFeatureInfo.html b/tests/Format/WMSGetFeatureInfo.html index 0445433373..be9b51d24d 100644 --- a/tests/Format/WMSGetFeatureInfo.html +++ b/tests/Format/WMSGetFeatureInfo.html @@ -52,7 +52,7 @@ } function test_read_msGMLOutput(t) { - t.plan(12); + t.plan(13); var parser = new OpenLayers.Format.WMSGetFeatureInfo(); @@ -69,6 +69,28 @@ t.eq(features.length, 0, "Parsing empty msGMLOutput response succesfull"); + // read empty attribute + text = + '' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 107397.266000,460681.063000 116568.188000,480609.250000' + + ' ' + + ' ' + + ' bar' + + ' ' + + ' ' + + ' ' + + ''; + features = parser.read(text); + t.eq((features[0].attributes.EMPTY === null), true, "Empty attribute is parsed as null"); + // read 1 feature from 1 layer text = '' +