You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/03/23 09:43:00 UTC

lucene-solr:branch_6x: GeoPointField now validates incoming lat/lon

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x f2234dccb -> 223568a23


GeoPointField now validates incoming lat/lon


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/223568a2
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/223568a2
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/223568a2

Branch: refs/heads/branch_6x
Commit: 223568a238de74d82c4b63bf940f2d96dbc01346
Parents: f2234dc
Author: Mike McCandless <mi...@apache.org>
Authored: Wed Mar 23 04:42:15 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Wed Mar 23 04:42:48 2016 -0400

----------------------------------------------------------------------
 .../spatial/geopoint/document/GeoPointField.java     | 13 +++++++++++--
 .../spatial/geopoint/search/TestGeoPointField.java   | 15 +++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/223568a2/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
index 688315a..00db23a 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
@@ -16,13 +16,14 @@
  */
 package org.apache.lucene.spatial.geopoint.document;
 
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
 import org.apache.lucene.index.DocValuesType;
 import org.apache.lucene.index.IndexOptions;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.spatial.util.GeoEncodingUtils;
+import org.apache.lucene.spatial.util.GeoUtils;
 
 /**
  * <p>
@@ -162,6 +163,14 @@ public final class GeoPointField extends Field {
   public GeoPointField(String name, double lat, double lon, FieldType type) {
     super(name, type);
 
+    if (GeoUtils.isValidLat(lat) == false) {
+      throw new IllegalArgumentException("invalid lat=" + lat + " for field \"" + name + "\"");
+    }
+
+    if (GeoUtils.isValidLon(lon) == false) {
+      throw new IllegalArgumentException("invalid lon=" + lon + " for field \"" + name + "\"");
+    }
+
     // field must be indexed
     // todo does it make sense here to provide the ability to store a GeoPointField but not index?
     if (type.indexOptions() == IndexOptions.NONE && type.stored() == false) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/223568a2/lucene/spatial/src/test/org/apache/lucene/spatial/geopoint/search/TestGeoPointField.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/geopoint/search/TestGeoPointField.java b/lucene/spatial/src/test/org/apache/lucene/spatial/geopoint/search/TestGeoPointField.java
index 41136b9..123769e 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/geopoint/search/TestGeoPointField.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/geopoint/search/TestGeoPointField.java
@@ -237,4 +237,19 @@ public class TestGeoPointField extends LuceneTestCase {
     TopDocs td = geoDistanceRangeQuery(0.0, 0.0, 10, 20000000, 20);
     assertEquals("GeoDistanceRangeQuery failed", 24, td.totalHits);
   }
+
+  public void testInvalidLatLon() throws Exception {
+    IllegalArgumentException e;
+    e= expectThrows(IllegalArgumentException.class,
+                    () -> {
+                      new GeoPointField("field", 180.0, 0.0, Field.Store.NO);
+                    });
+    assertEquals("invalid lat=180.0 for field \"field\"", e.getMessage());
+
+    e = expectThrows(IllegalArgumentException.class,
+                     () -> {
+                       new GeoPointField("field", 0.0, 190.0, Field.Store.NO);
+                     });
+    assertEquals("invalid lon=190.0 for field \"field\"", e.getMessage());
+  }
 }