Skip to content
/ server Public

MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry#4738

Open
abhishek593 wants to merge 1 commit intoMariaDB:10.11from
abhishek593:MDEV-34079
Open

MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry#4738
abhishek593 wants to merge 1 commit intoMariaDB:10.11from
abhishek593:MDEV-34079

Conversation

@abhishek593
Copy link

ST_AsGeoJSON stripped the first '[' bracket when serializing an EMPTY GeometryCollection, outputting '{"type": "GeometryCollection", "geometries":]}'.

This occurred because several Gis_*::get_data_as_json functions unconditionally truncated the last 2 characters of their String buffer to remove the trailing ', ' appended inside their element loops. For empty collections, the loop doesn't execute and there is no trailing comma, causing the truncate to strip the initial '[' bracket.

Fixed by checking if the last character in the buffer is ' ' before truncating.

ST_AsGeoJSON stripped the first '[' bracket when serializing an EMPTY
GeometryCollection, outputting '{"type": "GeometryCollection",
"geometries":]}'.

This occurred because several Gis_*::get_data_as_json functions
unconditionally truncated the last 2 characters of their String buffer
to remove the trailing ', ' appended inside their element loops. For
empty collections, the loop doesn't execute and there is no trailing
comma, causing the truncate to strip the initial '[' bracket.

Fixed by checking if the last character in the buffer is ' ' before
truncating.
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 6, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! This is a preliminary review.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

2 participants