Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Parameters not correctly decoded when comma is present #620

Open
nickschot opened this issue Jan 9, 2017 · 3 comments
Open

Query Parameters not correctly decoded when comma is present #620

nickschot opened this issue Jan 9, 2017 · 3 comments

Comments

@nickschot
Copy link
Contributor

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"
  }
}
@nickschot
Copy link
Contributor Author

nickschot commented Jan 16, 2017

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).

@nickschot
Copy link
Contributor Author

nickschot commented Jan 22, 2017

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.

@TheCodeSharman
Copy link

TheCodeSharman commented Oct 20, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants