summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Black <daniel@mariadb.org>2022-12-03 15:09:48 +1100
committerDaniel Black <daniel@mariadb.org>2022-12-09 08:49:43 +1100
commit8f3631d0096ceecc21f2879a9558fd9242f09f8c (patch)
treea3ef631a97bc58060e338983efc94d911ddf45e0
parentd360fa6fa897d9556dc3813e6f3366e01df8e715 (diff)
downloadmariadb-git-8f3631d0096ceecc21f2879a9558fd9242f09f8c.tar.gz
MDEV-30150 ST_GeomFromGeoJSON, 'geometry' before 'type: feature' error
The geometry type requires Type:"Feature" but the feature need not be first in the JSON structure. Adjust code to return an error if geometry isn't a JSON object, but continue parsing searching for Type: "Feature" to trigger the geometry parsing. Thanks Derick Magnusen for the bug report.
-rw-r--r--mysql-test/main/gis-json.result3
-rw-r--r--mysql-test/main/gis-json.test1
-rw-r--r--sql/spatial.cc3
3 files changed, 6 insertions, 1 deletions
diff --git a/mysql-test/main/gis-json.result b/mysql-test/main/gis-json.result
index ace9e9e9ae2..644684f5a73 100644
--- a/mysql-test/main/gis-json.result
+++ b/mysql-test/main/gis-json.result
@@ -58,6 +58,9 @@ Warning 4038 Syntax error in JSON text in argument 1 to function 'st_geomfromgeo
SELECT st_astext(st_geomfromgeojson('{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] } }'));
st_astext(st_geomfromgeojson('{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] } }'))
POINT(102 0.5)
+SELECT st_astext(st_geomfromgeojson('{ "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "type": "Feature" }'));
+st_astext(st_geomfromgeojson('{ "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "type": "Feature" }'))
+POINT(102 0.5)
SELECT st_astext(st_geomfromgeojson('{ "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": { "prop0": "value0" } }]}'));
st_astext(st_geomfromgeojson('{ "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": { "prop0": "value0" } }]}'))
GEOMETRYCOLLECTION(POINT(102 0.5))
diff --git a/mysql-test/main/gis-json.test b/mysql-test/main/gis-json.test
index 0e1b24a91b6..cda395acab5 100644
--- a/mysql-test/main/gis-json.test
+++ b/mysql-test/main/gis-json.test
@@ -26,6 +26,7 @@ SELECT st_astext(st_geomfromgeojson('{"type""point"}'));
#enable after fix MDEV-27871
--disable_view_protocol
SELECT st_astext(st_geomfromgeojson('{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] } }'));
+SELECT st_astext(st_geomfromgeojson('{ "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "type": "Feature" }'));
SELECT st_astext(st_geomfromgeojson('{ "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [102.0, 0.5] }, "properties": { "prop0": "value0" } }]}'));
diff --git a/sql/spatial.cc b/sql/spatial.cc
index 9a30d346a1c..e772a92c744 100644
--- a/sql/spatial.cc
+++ b/sql/spatial.cc
@@ -611,7 +611,8 @@ Geometry *Geometry::create_from_json(Geometry_buffer *buffer,
if (feature_type_found)
goto handle_geometry_key;
}
- goto err_return;
+ else
+ goto err_return;
}
else
{