lux
lux copied to clipboard
Query Parameters not correctly decoded when comma is present
In an (encoded) URL like /my-model?filter%5Bname%5D=MY%2C+Search+Term which is filter[name]= "MY, Search Term" what Lux ends up with in the controller is:
Params
{
"filter": {
"name": [
"mY",
" Search Term"
]
}
}
Which is clearly wrong. The URL as shown above is encoded by ember-data from passing:
{
filter: {
name: "MY, Search Term"
}
}
This is caused by formatString in /src/packages/server/request/parser/utils/format.jswhich splits on , in all cases. @zacharygolba why is this so? What data type as a value in the query parameters should be split on comma (apart from a future ?sort=val1,val2,val3)?
EDIT: comma's are used for many of the JSONAPI specified qp's (sort, include, sparse fieldsets for as far as I can see). We might wan't to check if the key is one of those and only split on comma when that is the case? This should be safe as qp's aren't really nested.
Another option is to check the controller attribute types and explode except when the type is string (though this might be prone to errors and mistakes in i.e. custom qp's).
~~This issue is not encountered when QP's not defined by Lux are used (i.e. search[name]=my, search term~~
Just checked, the issue is also there for custom QP's.
I'm also struggling with this - what is the correct way to escape the "," in a string to avoid this? AFAICT this isn't specified by the JSON API (http://jsonapi.org/format/#fetching-filtering). Edit: its used by Ember too by the looks of it when filtering by multiple ids.