mapbox / geobuf

A compact binary encoding for geographic data.
ISC License
967 stars 84 forks source link

keys can be serialized in the wrong order #90

Closed ivorblockley closed 6 years ago

ivorblockley commented 6 years ago

At least on my machine, geobuf failed to properly encode the following geojson:

{
  "type": "Feature",
  "" : "",
  "xyz" : null,
  "!" : {},
  "~" : [],
  "2" : [null],
  "properties": { "foo" : null, "" : null, "bar" : {} },
  "geometry": {
    "type": "Point",
    "coordinates": [100.0, 0.0]
  }
}

The property key order serialized was ["2", "foo", "", "bar", "xyz", "!", "~"] which did not match the order keys were encountered during encoding (and subsequently the order in which repeated values were stored which corresponded to a key order of ["foo", "", "bar", "2", "xyz", "!", "~"]).

I believe this can be fixed by ensuring keyArr in encode.js is generated via sorting "keys" by value.

mourner commented 6 years ago

Fixed in #93