Bounds-check array access in Polygon#initialize

This commit is contained in:
John Firebaugh 2013-05-02 16:17:04 -07:00
parent e032046119
commit c9e2453eed
2 changed files with 6 additions and 1 deletions

View File

@ -19,6 +19,11 @@ describe('Polygon', function() {
expect(sourceLatLngs).to.eql(originalLatLngs);
expect(polygon._latlngs).to.not.eql(sourceLatLngs);
});
it("can be called with an empty array", function () {
var polygon = new L.Polygon([]);
expect(polygon.getLatLngs()).to.eql([]);
});
});
describe("#setLatLngs", function () {

View File

@ -27,7 +27,7 @@ L.Polygon = L.Polyline.extend({
// filter out last point if its equal to the first one
latlngs = this._latlngs;
if (latlngs[0].equals(latlngs[latlngs.length - 1])) {
if (latlngs.length >= 2 && latlngs[0].equals(latlngs[latlngs.length - 1])) {
latlngs.pop();
}
},