Sanity check in LatLngBounds.contains (fixes #5132) (#5135)

This commit is contained in:
Iván Sánchez Ortega 2016-11-24 09:36:33 +01:00 committed by GitHub
parent 4f52a36dc1
commit 633182a836
2 changed files with 12 additions and 2 deletions

View File

@ -138,11 +138,21 @@ describe('LatLngBounds', function () {
});
describe('#contains', function () {
it('returns true if contains latlng point', function () {
it('returns true if contains latlng point as array', function () {
expect(a.contains([16, 20])).to.eql(true);
expect(L.latLngBounds(a).contains([5, 20])).to.eql(false);
});
it('returns true if contains latlng point as {lat:, lng:} object', function () {
expect(a.contains({lat: 16, lng: 20})).to.eql(true);
expect(L.latLngBounds(a).contains({lat: 5, lng: 20})).to.eql(false);
});
it('returns true if contains latlng point as L.LatLng instance', function () {
expect(a.contains(L.latLng([16, 20]))).to.eql(true);
expect(L.latLngBounds(a).contains(L.latLng([5, 20]))).to.eql(false);
});
it('returns true if contains bounds', function () {
expect(a.contains([[16, 20], [20, 40]])).to.eql(true);
expect(a.contains([[16, 50], [8, 40]])).to.eql(false);

View File

@ -150,7 +150,7 @@ L.LatLngBounds.prototype = {
// @method contains (latlng: LatLng): Boolean
// Returns `true` if the rectangle contains the given point.
contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean
if (typeof obj[0] === 'number' || obj instanceof L.LatLng) {
if (typeof obj[0] === 'number' || obj instanceof L.LatLng || 'lat' in obj) {
obj = L.latLng(obj);
} else {
obj = L.latLngBounds(obj);