Skip to content

Commit

Permalink
Fixes potential nullref exception on MultiGeometry
Browse files Browse the repository at this point in the history
When the MultiGeometry object doesn't have a geometries child this caused
a crash. Shouldn't crash, should just result in an invalid geoJson.
Added a test for this.
  • Loading branch information
vincentsels committed Jan 27, 2016
1 parent feb33b0 commit af620c9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var geometry = {
},
valid: function(_) {
return _ && _.type && (_.coordinates ||
_.type === 'GeometryCollection' && _.geometries.every(geometry.valid));
_.type === 'GeometryCollection' && _.geometries && _.geometries.every(geometry.valid));
},
any: function(_) {
if (geometry[_.type]) {
Expand Down
13 changes: 13 additions & 0 deletions test/data/geometrycollection_nogeometries.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ "type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "GeometryCollection"
},
"properties": {
"prop0": "value0",
"prop1": "val2"
}
}
]
}
1 change: 1 addition & 0 deletions test/data/geometrycollection_nogeometries.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document></Document></kml>
3 changes: 2 additions & 1 deletion test/kml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test('tokml', function(t) {
geq(tt, 'multipoint');
geq(tt, 'multipolygon');
geq(tt, 'geometrycollection');
geq(tt, 'geometrycollection_nogeometries');
tt.end();
});

Expand Down Expand Up @@ -144,7 +145,7 @@ test('tokml', function(t) {
try {
tokml(gen);
} catch(e) {
tt.fail('failed ' + JSON.stringify(gen) + 'with ' + e + e.stack);
tt.fail('failed at fuzzed version of ' + gj + ': ' + JSON.stringify(gen) + 'with ' + e + e.stack);
}
}
});
Expand Down

0 comments on commit af620c9

Please sign in to comment.