From bb5f4ddd755e00a3f602d2ca88ecd07e9e2fae0b Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 10 Sep 2019 14:15:28 +0200 Subject: [PATCH] LUCENE-8964: Fix geojson shape parsing on string arrays in properties (#866) --- lucene/CHANGES.txt | 3 +++ .../lucene/geo/SimpleGeoJSONPolygonParser.java | 2 ++ .../test/org/apache/lucene/geo/TestPolygon.java | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 20fb0ae3a7b..10df563b99a 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -70,6 +70,9 @@ Improvements * LUCENE-8620: Tessellator labels the edges of the generated triangles whether they belong to the original polygon. This information is added to the triangle encoding. (Ignacio Vera) +* LUCENE-8964: Fix geojson shape parsing on string arrays in properties + (Alexander Reelsen) + Optimizations * LUCENE-8922: DisjunctionMaxQuery more efficiently leverages impacts to skip diff --git a/lucene/core/src/java/org/apache/lucene/geo/SimpleGeoJSONPolygonParser.java b/lucene/core/src/java/org/apache/lucene/geo/SimpleGeoJSONPolygonParser.java index 1e35a3db8c4..d33d11acf5f 100644 --- a/lucene/core/src/java/org/apache/lucene/geo/SimpleGeoJSONPolygonParser.java +++ b/lucene/core/src/java/org/apache/lucene/geo/SimpleGeoJSONPolygonParser.java @@ -295,6 +295,8 @@ class SimpleGeoJSONPolygonParser { o = null; } else if (ch == '-' || ch == '.' || (ch >= '0' && ch <= '9')) { o = parseNumber(); + } else if (ch == '"') { + o = parseString(); } else { throw newParseException("expected another array or number while parsing array, not '" + ch + "'"); } diff --git a/lucene/core/src/test/org/apache/lucene/geo/TestPolygon.java b/lucene/core/src/test/org/apache/lucene/geo/TestPolygon.java index 8ee62718e6d..e9bf265ffb5 100644 --- a/lucene/core/src/test/org/apache/lucene/geo/TestPolygon.java +++ b/lucene/core/src/test/org/apache/lucene/geo/TestPolygon.java @@ -300,4 +300,21 @@ public class TestPolygon extends LuceneTestCase { Exception e = expectThrows(ParseException.class, () -> Polygon.fromGeoJSON(b.toString())); assertTrue(e.getMessage().contains("can only handle type FeatureCollection (if it has a single polygon geometry), Feature, Polygon or MutiPolygon, but got Point")); } + + public void testPolygonPropertiesCanBeStringArrays() throws Exception { + StringBuilder b = new StringBuilder(); + b.append("{\n"); + b.append(" \"type\": \"Polygon\",\n"); + b.append(" \"coordinates\": [\n"); + b.append(" [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],\n"); + b.append(" [100.0, 1.0], [100.0, 0.0] ]\n"); + b.append(" ],\n"); + b.append(" \"properties\": {\n"); + b.append(" \"array\": [ \"value\" ]\n"); + b.append(" }\n"); + b.append("}\n"); + + Polygon[] polygons = Polygon.fromGeoJSON(b.toString()); + assertEquals(1, polygons.length); + } }