Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions mysql-test/main/gis-json.result
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,22 @@ Warning 4048 Incorrect GeoJSON format specified for st_geomfromgeojson function.
#
# End of 10.2 tests
#
#
# MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry
#
SELECT ST_AsGeoJSON(GeomFromText('GeometryCollection EMPTY'));
ST_AsGeoJSON(GeomFromText('GeometryCollection EMPTY'))
{"type": "GeometryCollection", "geometries": []}
SELECT ST_AsGeoJSON(ST_DIFFERENCE(POINT(0,0), POINT(0,0)));
ST_AsGeoJSON(ST_DIFFERENCE(POINT(0,0), POINT(0,0)))
{"type": "GeometryCollection", "geometries": []}
SELECT ST_AsGeoJSON(GeomFromText('MultiPoint EMPTY'));
ST_AsGeoJSON(GeomFromText('MultiPoint EMPTY'))
NULL
SELECT ST_AsGeoJSON(GeomFromText('MultiLineString EMPTY'));
ST_AsGeoJSON(GeomFromText('MultiLineString EMPTY'))
NULL
SELECT ST_AsGeoJSON(GeomFromText('MultiPolygon EMPTY'));
ST_AsGeoJSON(GeomFromText('MultiPolygon EMPTY'))
NULL
# End of 10.11 tests
11 changes: 11 additions & 0 deletions mysql-test/main/gis-json.test
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ SELECT ST_ASTEXT(ST_GEOMFROMGEOJSON('{"type": ["POINT"], "coINates": [0,0] }'))
--echo #
--echo # End of 10.2 tests
--echo #
--echo #
--echo # MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry
--echo #

SELECT ST_AsGeoJSON(GeomFromText('GeometryCollection EMPTY'));
SELECT ST_AsGeoJSON(ST_DIFFERENCE(POINT(0,0), POINT(0,0)));
SELECT ST_AsGeoJSON(GeomFromText('MultiPoint EMPTY'));
SELECT ST_AsGeoJSON(GeomFromText('MultiLineString EMPTY'));
SELECT ST_AsGeoJSON(GeomFromText('MultiPolygon EMPTY'));

--echo # End of 10.11 tests
15 changes: 10 additions & 5 deletions sql/spatial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,8 @@ static const char *append_json_points(String *txt, uint max_dec,
data+= POINT_DATA_SIZE;
txt->qs_append(", ", 2);
}
txt->length(txt->length() - 2);// Remove ending ', '
if (txt->ptr()[txt->length() - 1] == ' ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more comfortable if you save and check n_points instead. Here and everyplace else you are changing.

txt->length(txt->length() - 2);// Remove ending ', '
txt->qs_append(']');
return data;
}
Expand Down Expand Up @@ -1761,7 +1762,8 @@ bool Gis_polygon::get_data_as_json(String *txt, uint max_dec_digits,
data= append_json_points(txt, max_dec_digits, n_points, data, 0);
txt->qs_append(", ", 2);
}
txt->length(txt->length() - 2);// Remove ending ', '
if (txt->ptr()[txt->length() - 1] == ' ')
txt->length(txt->length() - 2);// Remove ending ', '
txt->qs_append(']');
*end= data;
return 0;
Expand Down Expand Up @@ -2636,7 +2638,8 @@ bool Gis_multi_line_string::get_data_as_json(String *txt, uint max_dec_digits,
data= append_json_points(txt, max_dec_digits, n_points, data, 0);
txt->qs_append(", ", 2);
}
txt->length(txt->length() - 2);
if (txt->ptr()[txt->length() - 1] == ' ')
txt->length(txt->length() - 2);
txt->qs_append(']');
*end= data;
return 0;
Expand Down Expand Up @@ -3059,7 +3062,8 @@ bool Gis_multi_polygon::get_data_as_json(String *txt, uint max_dec_digits,
txt->length(txt->length() - 2);
txt->qs_append("], ", 3);
}
txt->length(txt->length() - 2);
if (txt->ptr()[txt->length() - 1] == ' ')
txt->length(txt->length() - 2);
txt->q_append(']');
*end= data;
return 0;
Expand Down Expand Up @@ -3529,7 +3533,8 @@ bool Gis_geometry_collection::get_data_as_json(String *txt, uint max_dec_digits,
txt->append(STRING_WITH_LEN("}, "), 512))
return 1;
}
txt->length(txt->length() - 2);
if (txt->ptr()[txt->length() - 1] == ' ')
txt->length(txt->length() - 2);
if (txt->append(']'))
return 1;

Expand Down