summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/gis-json.result15
-rw-r--r--mysql-test/t/gis-json.test4
-rw-r--r--sql/item_geofunc.cc3
-rw-r--r--sql/share/errmsg-utf8.txt3
-rw-r--r--sql/spatial.cc35
-rw-r--r--sql/spatial.h1
6 files changed, 60 insertions, 1 deletions
diff --git a/mysql-test/r/gis-json.result b/mysql-test/r/gis-json.result
index d888b08351d..1d6e2193fc9 100644
--- a/mysql-test/r/gis-json.result
+++ b/mysql-test/r/gis-json.result
@@ -89,6 +89,21 @@ ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 1)
SELECT ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 5);
ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 5)
{"bbox": [10, 11, 10, 11], "type": "Point", "coordinates": [10, 11]}
+SELECT st_astext(st_geomfromgeojson('{"type": "MultiLineString","coordinates": []}')) as a;
+a
+NULL
+Warnings:
+Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
+SELECT st_astext(st_geomfromgeojson('{"type": "Polygon","coordinates": []}')) as a;
+a
+NULL
+Warnings:
+Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
+SELECT st_astext(st_geomfromgeojson('{"type": "MultiPolygon","coordinates": []}')) as a;
+a
+NULL
+Warnings:
+Warning 4076 Incorrect GeoJSON format - empty 'coordinates' array.
#
# End of 10.2 tests
#
diff --git a/mysql-test/t/gis-json.test b/mysql-test/t/gis-json.test
index 5e695fbca9c..b91ef235fd0 100644
--- a/mysql-test/t/gis-json.test
+++ b/mysql-test/t/gis-json.test
@@ -40,6 +40,10 @@ SELECT ST_AsGeoJSON(ST_GeomFromText('POINT(5.363 7.266)'),10);
SELECT ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 1);
SELECT ST_AsGeoJSON(ST_GeomFromText("POINT(10 11)"), 100, 5);
+SELECT st_astext(st_geomfromgeojson('{"type": "MultiLineString","coordinates": []}')) as a;
+SELECT st_astext(st_geomfromgeojson('{"type": "Polygon","coordinates": []}')) as a;
+SELECT st_astext(st_geomfromgeojson('{"type": "MultiPolygon","coordinates": []}')) as a;
+
--echo #
--echo # End of 10.2 tests
--echo #
diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc
index 6f79bd9a039..3119f5a577b 100644
--- a/sql/item_geofunc.cc
+++ b/sql/item_geofunc.cc
@@ -174,6 +174,9 @@ String *Item_func_geometry_from_json::val_str(String *str)
case Geometry::GEOJ_TOO_FEW_POINTS:
code= ER_GEOJSON_TOO_FEW_POINTS;
break;
+ case Geometry::GEOJ_EMPTY_COORDINATES:
+ code= ER_GEOJSON_EMPTY_COORDINATES;
+ break;
case Geometry::GEOJ_POLYGON_NOT_CLOSED:
code= ER_GEOJSON_NOT_CLOSED;
break;
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 554b6c7afec..0e93f0546c9 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7746,3 +7746,6 @@ ER_SUM_FUNC_WITH_WINDOW_FUNC_AS_ARG
ER_NET_OK_PACKET_TOO_LARGE
eng "OK packet too large"
+
+ER_GEOJSON_EMPTY_COORDINATES
+ eng "Incorrect GeoJSON format - empty 'coordinates' array."
diff --git a/sql/spatial.cc b/sql/spatial.cc
index 357e311543f..2aca528dd15 100644
--- a/sql/spatial.cc
+++ b/sql/spatial.cc
@@ -1041,7 +1041,7 @@ bool Gis_line_string::init_from_json(json_engine_t *je, bool er_on_3D,
}
if (n_points < 1)
{
- je->s.error= GEOJ_TOO_FEW_POINTS;
+ je->s.error= Geometry::GEOJ_TOO_FEW_POINTS;
return TRUE;
}
wkb->write_at_position(np_pos, n_points);
@@ -1440,6 +1440,15 @@ bool Gis_polygon::init_from_json(json_engine_t *je, bool er_on_3D, String *wkb)
}
n_linear_rings++;
}
+
+ if (je->s.error)
+ return TRUE;
+
+ if (n_linear_rings == 0)
+ {
+ je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
+ return TRUE;
+ }
wkb->write_at_position(lr_pos, n_linear_rings);
return FALSE;
}
@@ -1945,6 +1954,14 @@ bool Gis_multi_point::init_from_json(json_engine_t *je, bool er_on_3D,
n_points++;
}
+ if (je->s.error)
+ return TRUE;
+ if (n_points == 0)
+ {
+ je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
+ return TRUE;
+ }
+
wkb->write_at_position(np_pos, n_points);
return FALSE;
}
@@ -2214,6 +2231,15 @@ bool Gis_multi_line_string::init_from_json(json_engine_t *je, bool er_on_3D,
n_line_strings++;
}
+ if (je->s.error)
+ return TRUE;
+
+ if (n_line_strings == 0)
+ {
+ je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
+ return TRUE;
+ }
+
wkb->write_at_position(ls_pos, n_line_strings);
return FALSE;
}
@@ -2603,6 +2629,13 @@ bool Gis_multi_polygon::init_from_json(json_engine_t *je, bool er_on_3D,
n_polygons++;
}
+ if (je->s.error)
+ return TRUE;
+ if (n_polygons == 0)
+ {
+ je->s.error= Geometry::GEOJ_EMPTY_COORDINATES;
+ return TRUE;
+ }
wkb->write_at_position(np_pos, n_polygons);
return FALSE;
}
diff --git a/sql/spatial.h b/sql/spatial.h
index 78e850dc2d7..901544b6916 100644
--- a/sql/spatial.h
+++ b/sql/spatial.h
@@ -256,6 +256,7 @@ public:
GEOJ_TOO_FEW_POINTS= 2,
GEOJ_POLYGON_NOT_CLOSED= 3,
GEOJ_DIMENSION_NOT_SUPPORTED= 4,
+ GEOJ_EMPTY_COORDINATES= 5,
};