make sure we can also read in CDATA fields with newlines

This commit is contained in:
Bart van den Eijnden
2013-11-27 16:09:36 +01:00
parent 9895c0f084
commit 73a2ab2de1
2 changed files with 14 additions and 1 deletions

View File

@@ -75,7 +75,7 @@ ol.parser.KML = function(opt_options) {
'*': function(node, obj) {
if (this.extractAttributes === true) {
var len = node.childNodes.length;
if ((len === 1 || len === 2) && (node.firstChild.nodeType === 3 ||
if (len > 0 && (node.firstChild.nodeType === 3 ||
node.firstChild.nodeType === 4)) {
var readers = this.readers[this.defaultNamespaceURI];
readers['_attribute'].apply(this, arguments);

View File

@@ -163,6 +163,19 @@ describe('ol.parser.KML', function() {
expect(obj.features[0].get('description')).to.eql('Full of text.');
expect(obj.features[0].get('name')).to.eql('Pezinok');
});
it('Test CDATA attributes with newlines', function() {
var cdata = '<kml xmlns="http://earth.google.com/kml/2.0"><Document>' +
'<Placemark><name><![CDATA[Pezinok]]> </name><description>' +
'\n' +
'<![CDATA[Full of text.]]>' +
'\n' +
'</description><styleUrl>#rel1.0' +
'</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates>' +
'</Point></Placemark></Document></kml>';
var obj = parser.read(cdata);
expect(obj.features[0].get('description')).to.eql('Full of text.');
expect(obj.features[0].get('name')).to.eql('Pezinok');
});
it('handles line style (read / write)', function() {
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +