From f4fbc960361307db03822f592142e9366aedb1d7 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sun, 21 Mar 2010 21:10:33 +0000 Subject: [PATCH] fixed KML parsing for cases where a line break is only before or after a CDATA block. r=bartvde (closes #2398) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10138 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/KML.js | 8 +++++++- tests/Format/KML.html | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Format/KML.js b/lib/OpenLayers/Format/KML.js index b98d18f912..e8ccba5060 100644 --- a/lib/OpenLayers/Format/KML.js +++ b/lib/OpenLayers/Format/KML.js @@ -885,12 +885,18 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, { child = children[i]; if(child.nodeType == 1) { grandchildren = child.childNodes; - if(grandchildren.length == 1 || grandchildren.length == 3) { + if(grandchildren.length >= 1 || grandchildren.length <= 3) { var grandchild; switch (grandchildren.length) { case 1: grandchild = grandchildren[0]; break; + case 2: + var c1 = grandchildren[0]; + var c2 = grandchildren[1]; + grandchild = c1.nodeType == 3 || c1.nodeType == 4 ? + c1 : c2; + break; case 3: default: grandchild = grandchildren[1]; diff --git a/tests/Format/KML.html b/tests/Format/KML.html index c09724b3f5..8f294e4202 100644 --- a/tests/Format/KML.html +++ b/tests/Format/KML.html @@ -37,7 +37,7 @@ function test_Format_KML_readCdataAttributes_20(t) { t.plan(2); - var cdata = '#rel1.0 17.266666, 48.283333'; + var cdata = ' #rel1.0 17.266666, 48.283333'; var features = (new OpenLayers.Format.KML()).read(cdata); t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly"); t.eq(features[0].attributes.name, "Pezinok", "title attribute in cdata read correctly");