danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
717 stars 69 forks source link

gron output fails on keys containing "." #217

Closed mpol closed 9 months ago

mpol commented 10 months ago

See example:

$ restish --version
restish version 0.18.0

$ echo '{"a.b":["x"],"c.d":["y"]}'|restish https://api.rest.sh/ -o gron|grep parsed
body.parsed = {};
body.parsed["a.b"] = [];
body.parsed["a.b"][0] = "x";
body.parsed["a["c.d"] = [];
body.parsed["a["c.d"][0] = "y";
body.parsed["a.path = "/";
body.parsed["a.url = "https://api.rest.sh/";
danielgtaylor commented 10 months ago

A quick look tells me this is likely the PathBuffer().Pop() returning too early because it doesn't know that the a.b is one path component. Shouldn't be too hard to fix but it'll need some way to push escaped keys and pop off the whole key, not just part of it.

mpol commented 10 months ago

Yes. The same problem is caused by a [ bracket in the key and while a " quote in the key is popped correctly, it is unquoted in output, giving eg. body.parsed["a"b"] = "x";.