kinto icon indicating copy to clipboard operation
kinto copied to clipboard

Keys with special characters can't be referenced in filters

Open lesderid opened this issue 10 months ago • 4 comments

If an object key contains special characters (e.g. - or .), it can't be filtered on even though it's a valid JSON object key.

For example, ?has_stuff.foo-bar=true can't be used to check if "foo-bar" is a field of "stuff". There doesn't seem to be any way to escape special characters either.

lesderid avatar Jan 27 '25 01:01 lesderid

Indeed!

How do you think we could solve this? Using quotes I guess? ?has_stuff."foo-bar"=true?

leplatrem avatar Jan 27 '25 09:01 leplatrem

How do you think we could solve this? Using quotes I guess? ?has_stuff."foo-bar"=true?

There seem to be a few options:

Syntax jq JSONPath
.stuff."foo-bar"
.stuff.["foo-bar"]
.stuff["foo-bar"] ✅[^1]
.stuff['foo-bar']

[^1]: While this works, I can't find it specified in the docs.

Edit: For what it's worth, I don't have a particularly strong preference. I think the first one is probably the most intuitive though.

lesderid avatar Jan 27 '25 12:01 lesderid

Thanks for the reference 👌

If we can't have both, I think I would prefer if we would follow a IETF standard. We could replace the jsonpatch lib we currently use with this one that seems to support both JSONPath and JSONPatch.

The code that handles the querystring filters is here:

https://github.com/Kinto/kinto/blob/80f43155b092cb2a01ba67c95334733553d9bd64/kinto/core/resource/init.py#L1108

And filters are then implemented in each storage down the line:

https://github.com/Kinto/kinto/blob/5ea7d6048b3a090c7de7521154d87216e25f04a3/kinto/core/storage/memory.py#L511

https://github.com/Kinto/kinto/blob/1c2355979d610c9e92bbeb898978add9052505ea/kinto/core/storage/postgresql/init.py#L785-L787

With tests for both:

https://github.com/Kinto/kinto/blob/bf944381f56d63d13c52adfbfe4b351df8c3807d/tests/core/resource/test_filter.py#L251-L261

https://github.com/Kinto/kinto/blob/1c2355979d610c9e92bbeb898978add9052505ea/kinto/core/storage/testing.py#L710-L722

Would you like to try a contribution?

leplatrem avatar Jan 27 '25 13:01 leplatrem

Can you assign it to me? @leplatrem , I would like to contribute in it.

KritimPrasadKafle avatar May 28 '25 17:05 KritimPrasadKafle