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

fix: previously unsurported array-style query variants #2730

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tsebas
Copy link

@tsebas tsebas commented Mar 26, 2024

There seems to be a lack of standardization when it comes to encoding arrays in the query parameters, in general.

  1. The now deprecated request module for example seems to use the indexed array approach, foo[0]=bar1&foo[2]=bar2.
  2. Axios seems to prefer the unindexed array approach, i.e. foo[]=bar1&foo[]=bar2
  3. there is also the implicit array approach where the parameter becomes an array if it appears multiple times, i.e. foo=bar1&foo=bar2

Nock is able to handle 1 and 3 with the current code, but not 2, which is the default serialization from Axios. One could in principle just resort to a different serialization, and in fact axios support the option of serializing the parameters if any of the above approaches. However, it makes sense for Nock to support cleanly all 3 since it is being used to test APIs and for that reason it shouldn't be enforcing 1 approach over another.

@tsebas
Copy link
Author

tsebas commented Mar 26, 2024

It adds 1 test for case 2, and unlike the other tests it focuses only on array parsing, and it doesn't mix other kinds of parameters. While I disagree in general with the exact structure of those tests, I can make mine look more like them, by adding handling of other parameters as well.

Ps.: I was going to submit a Github issue, but since the code turned out easy to understand, modify and test, I decided to just proceed with that instead. Please let me know if you'd want me to follow another process, if this is inadequate.

@tsebas tsebas changed the title fix: previously unsurported array-style queyr variants fix: previously unsurported array-style query variants Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant