mapbox / mapboxgl-jupyter

Use Mapbox GL JS to visualize data in a Python Jupyter notebook
MIT License
661 stars 136 forks source link

MapboxGL Jupyter doesn't sanitise GeoJSON dict before passing it to the JS layer #155

Open aidanlister opened 5 years ago

aidanlister commented 5 years ago

If you pass a GeoJSON dict with single apostrophee's in it, the notebook fails to render the map eg:

{ ... 'properties': {'address': 'foo 'bar'}}
akacarlyann commented 5 years ago

@aidanlister does your data pass muster with a GeoJSON linter tool? Mapboxgl-jupyter does assume the input data is a valid JSON object, Python dictionary, or DataFrame.

aidanlister commented 3 years ago

@akacarlyann it's not serialising the data properly when writing it to a file ... it's nothing to do with the input (e.g. an apostrophe in property shouldn't crash the script).

jdtoy commented 1 year ago

Think I've found the bug. Can anyone explain why this line exists? (Paging @perrygeo)

https://github.com/mapbox/mapboxgl-jupyter/blob/be12374b0653db334e7ff8d56fab28db27d832c7/mapboxgl/viz.py#L247

This is done when building the iframe, after (valid) geojson and html is produced.

The effect is to mangle the geojson in the html.

Property strings which were in the form:

{ ... 'properties': {'address': "someone's place"}}

are converted to being wraped by single quotes:

{ ... 'properties': {'address': 'someone's place'}}

breaking the json, javascript, and map.