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:40:54 UTC
lucene-solr:master: GeoPointField now validates incoming lat/lon
Repository: lucene-solr
Updated Branches:
refs/heads/master 574da7667 -> 6a5e935aa
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/6a5e935a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6a5e935a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6a5e935a
Branch: refs/heads/master
Commit: 6a5e935aa6fa671fccee1872828b301b0b69a4da
Parents: 574da76
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:15 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/6a5e935a/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/6a5e935a/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());
+ }
}