Skip to content

Commit

Permalink
Merge pull request #1456 from mapbox/1443-lnglat-throw
Browse files Browse the repository at this point in the history
Throw on lat > 90 || < -90. Fixes #1443
  • Loading branch information
mourner committed Sep 7, 2015
2 parents a459632 + 2c2bd6e commit 6e29593
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions js/geo/lng_lat.js
Expand Up @@ -20,6 +20,9 @@ function LngLat(lng, lat) {
}
this.lng = +lng;
this.lat = +lat;
if (this.lat > 90 || this.lat < -90) {
throw new Error('Invalid LngLat latitude value: must be between -90 and 90');
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test/js/geo/lng_lat.test.js
Expand Up @@ -10,6 +10,14 @@ test('LngLat', function(t) {
/*eslint no-new: 0*/
new LngLat('foo', 0);
}, "Invalid LngLat object: (foo, 0)", 'detects and throws on invalid input');
t.throws(function() {
/*eslint no-new: 0*/
new LngLat(0, -91);
}, 'Invalid LngLat latitude value: must be between -90 and 90', 'detects and throws on invalid input');
t.throws(function() {
/*eslint no-new: 0*/
new LngLat(0, 91);
}, 'Invalid LngLat latitude value: must be between -90 and 90', 'detects and throws on invalid input');
t.end();
});

Expand Down

0 comments on commit 6e29593

Please sign in to comment.