summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo
diff options
context:
space:
mode:
authorHari Khalsa <hkhalsa@10gen.com>2013-03-25 11:01:40 -0400
committerHari Khalsa <hkhalsa@10gen.com>2013-03-27 09:37:49 -0400
commit2ef273f283c7d45b9dfa55f5adf14f2b63069dc7 (patch)
tree41a89b6db7c59f59b4ef40ccb38a0c4d1f4af47a /src/mongo/db/geo
parent7b84af64e01ae93f0315dcd3c492f44e044adb24 (diff)
downloadmongo-2ef273f283c7d45b9dfa55f5adf14f2b63069dc7.tar.gz
SERVER-9062 don't rely on drem to normalize longitude -- explicitly reject OOB values
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r--src/mongo/db/geo/geoparser.cpp5
-rw-r--r--src/mongo/db/geo/geoparser_test.cpp15
2 files changed, 19 insertions, 1 deletions
diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp
index 3b53b30cdd2..f74022dde76 100644
--- a/src/mongo/db/geo/geoparser.cpp
+++ b/src/mongo/db/geo/geoparser.cpp
@@ -68,7 +68,9 @@ namespace mongo {
}
// ...where the latitude is valid
double lat = thisCoord[1].Number();
+ double lng = thisCoord[0].Number();
if (lat < -90 || lat > 90) { return false; }
+ if (lng < -180 || lng > 180) { return false; }
}
return true;
}
@@ -101,7 +103,8 @@ namespace mongo {
if (coordinates.size() != 2) { return false; }
if (!coordinates[0].isNumber() || !coordinates[1].isNumber()) { return false; }
double lat = coordinates[1].Number();
- return lat >= -90 && lat <= 90;
+ double lng = coordinates[0].Number();
+ return lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
}
void GeoParser::parseGeoJSONPoint(const BSONObj& obj, S2Cell* out) {
diff --git a/src/mongo/db/geo/geoparser_test.cpp b/src/mongo/db/geo/geoparser_test.cpp
index 2e7fffb515f..cb3af1a119e 100644
--- a/src/mongo/db/geo/geoparser_test.cpp
+++ b/src/mongo/db/geo/geoparser_test.cpp
@@ -54,6 +54,10 @@ namespace {
// Make sure lat is in range
ASSERT_TRUE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [0, 90.0]}")));
ASSERT_TRUE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [0, -90.0]}")));
+ ASSERT_TRUE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [180, 90.0]}")));
+ ASSERT_TRUE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [-180, -90.0]}")));
+ ASSERT_FALSE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [180.01, 90.0]}")));
+ ASSERT_FALSE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [-180.01, -90.0]}")));
ASSERT_FALSE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [0, 90.1]}")));
ASSERT_FALSE(GeoParser::isPoint(fromjson("{'type':'Point', 'coordinates': [0, -90.1]}")));
}
@@ -63,6 +67,10 @@ namespace {
fromjson("{'type':'LineString', 'coordinates':[[1,2], [3,4]]}")));
ASSERT_TRUE(GeoParser::isLineString(
fromjson("{'type':'LineString', 'coordinates':[[0,-90], [0,90]]}")));
+ ASSERT_TRUE(GeoParser::isLineString(
+ fromjson("{'type':'LineString', 'coordinates':[[180,-90], [-180,90]]}")));
+ ASSERT_FALSE(GeoParser::isLineString(
+ fromjson("{'type':'LineString', 'coordinates':[[180.1,-90], [-180.1,90]]}")));
ASSERT_FALSE(GeoParser::isLineString(
fromjson("{'type':'LineString', 'coordinates':[[0,-91], [0,90]]}")));
ASSERT_FALSE(GeoParser::isLineString(
@@ -82,6 +90,13 @@ namespace {
TEST(GeoParser, isValidPolygon) {
ASSERT_TRUE(GeoParser::isPolygon(
fromjson("{'type':'Polygon', 'coordinates':[ [[0,0],[5,0],[5,5],[0,5],[0,0]] ]}")));
+ // No out of bounds points
+ ASSERT_FALSE(GeoParser::isPolygon(
+ fromjson("{'type':'Polygon', 'coordinates':[ [[0,0],[5,0],[5,91],[0,5],[0,0]] ]}")));
+ ASSERT_TRUE(GeoParser::isPolygon(
+ fromjson("{'type':'Polygon', 'coordinates':[ [[0,0],[180,0],[5,5],[0,5],[0,0]] ]}")));
+ ASSERT_FALSE(GeoParser::isPolygon(
+ fromjson("{'type':'Polygon', 'coordinates':[ [[0,0],[181,0],[5,5],[0,5],[0,0]] ]}")));
// And one with a hole.
ASSERT_TRUE(GeoParser::isPolygon(
fromjson("{'type':'Polygon', 'coordinates':[ [[0,0],[5,0],[5,5],[0,5],[0,0]],"