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 with Map values are not properly encoded #283

Closed
point-source opened this issue Aug 10, 2021 · 5 comments
Closed

Query parameters with Map values are not properly encoded #283

point-source opened this issue Aug 10, 2021 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@point-source
Copy link

Using chopper 4.0.1, I am trying to encode a query param called "filter" which accepts a map with this structure:

{
  "Field": "QuoteNumber",
  "Op": "=",
  "Value": "306142"
}

The correct encoding of this is:

filter=%7B%0A%20%20%22Field%22%3A%20%22QuoteNumber%22%2C%0A%20%20%22Op%22%3A%20%22%3D%22%2C%0A%20%20%22Value%22%3A%20%22306142%22%0A%7D

But chopper encodes it as:

filter=%7BField%3A+QuoteNumber%2C+Op%3A+%3D%2C+Value%3A+306142%7D

which gets decoded to:

{Field:+QuoteNumber,+Op:+=,+Value:+306142}

This is obviously not valid json for a number of reasons and as a result, the server throws a 400 or 500 error.

@techouse
Copy link
Collaborator

techouse commented Oct 5, 2022

You could simply encode that map into a JSON string using json.encode() and pass it as a String.

@point-source
Copy link
Author

True. But this is happening within a library generator that uses chopper as a dependency. I'd rather see it fixed than convince the author of the generator(s) to work around it.

@point-source
Copy link
Author

Furthermore, if formatting of the value is required prior to passing it to chopper, then chopper should specify the type it expects (such as string) or throw when an unencodable type is used.

@techouse
Copy link
Collaborator

techouse commented Mar 11, 2023

@point-source This should have been fixed in this PR already #364

{
  "Field": "QuoteNumber",
  "Op": "=",
  "Value": "306142"
}

would get encoded as

hxxp://path.to/api/?filter.Field=QuoteNumber&filter.Op=%3D&filter.Value=306142

Check the PR comments for more examples.

@point-source
Copy link
Author

Great to know, thanks!

@techouse techouse self-assigned this Mar 12, 2023
@techouse techouse added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants