visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.26k stars 2.08k forks source link

Pydeck layer serialization strips internal quotes #4507

Open kylebarron opened 4 years ago

kylebarron commented 4 years ago

cc @ajduberstein

Description

When passing a string to Pydeck, all internal (double) quote characters are removed. This prevents passing JSON data as a string to JS.

Repro Steps

Note that this can be reproduced solely in Python. I.e. before doing any serialization, the quotes have already been stripped.

import pydeck as pdk
json_str = '"{"hello":"world"}"'
layer = pdk.Layer(
    "Layer",
    None,
    json=json_str)
layer
{"@@type": "Layer",
 "id": "6e7e67aa-7b5c-47ab-928f-508fb6af892e",
 "json": "{hello:world}"}

I would expect escaped \" to exist in the internal string object

Environment (please complete the following information):

Logs

kylebarron commented 4 years ago

This has a rather simple solution: https://github.com/visgl/deck.gl/blob/7b3b615edb86c7a6adf9230bdcb139a58e9933d3/bindings/pydeck/pydeck/bindings/layer.py#L93 Here, if the first and last characters are ", then every instance of " is removed in the string.

In order to not remove internal quotes, this could be changed to only remove the first and last characters.