diff --git a/src/ol/parser/kmlparser.js b/src/ol/parser/kmlparser.js
index 1fecd92d39..a815485d7f 100644
--- a/src/ol/parser/kmlparser.js
+++ b/src/ol/parser/kmlparser.js
@@ -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);
diff --git a/test/spec/ol/parser/kml.test.js b/test/spec/ol/parser/kml.test.js
index 4fb7774edc..4a165f055b 100644
--- a/test/spec/ol/parser/kml.test.js
+++ b/test/spec/ol/parser/kml.test.js
@@ -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 = '' +
+ ' ' +
+ '\n' +
+ '' +
+ '\n' +
+ '#rel1.0' +
+ ' 17.266666, 48.283333' +
+ '';
+ 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 = '