Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug of GeoJSONWriter when there are sub-objects or sub-array in an array #1216

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kunlinyu
Copy link
Contributor

@kunlinyu kunlinyu commented Jan 2, 2025

GeoJSONWriter will throw exception when handle these two cases:

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [ 0, 0 ]
  },
  "properties": {
    "matrix": [
      [ 1, 2, 3 ],
      [ 4, 5, 6 ]
    ]
  }
}
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [ 0, 0 ]
  },
  "properties": {
    "array": [
      { "key": "value_1" },
      { "key": "value_2" }
    ]
  }
}

the message of the exception is :

cannot use operator[] with a string argument with array

The root cause is here:
https://github.com/libgeos/geos/blob/3.13.0/src/io/GeoJSONWriter.cpp#L112
https://github.com/libgeos/geos/blob/3.13.0/src/io/GeoJSONWriter.cpp#L118

All other scalar types will detect the parent node is object or array.
If the parent is object then use key to add child value, else use push_back.
But when it comes to value.is_array() and value.is_object(), we forget to detect the type of parent json node.

So I add two unit tests to trigger the bug and fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants