MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry#4738
Open
abhishek593 wants to merge 1 commit intoMariaDB:10.11from
Open
MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry#4738abhishek593 wants to merge 1 commit intoMariaDB:10.11from
abhishek593 wants to merge 1 commit intoMariaDB:10.11from
Conversation
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
requested changes
Mar 6, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
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] == ' ') |
Member
There was a problem hiding this comment.
I'd be more comfortable if you save and check n_points instead. Here and everyplace else you are changing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.