Skip to content

feat: add new acceptNonStandardSearchParameters MockAgent option #4148

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

Conversation

dario-piotrowicz
Copy link
Member

@dario-piotrowicz dario-piotrowicz commented Apr 4, 2025

Rationale

This PR adds a new acceptNonStandardSearchParameters option to make
instances of MockAgent accept search parameters specified
using non-standard syntaxes such as multi-value items specified with []
(e.g. param[]=1&param[]=2&param[]=3) and multi-value items which values
are comma separated (e.g. param=1,2,3)

With these changes MockAgent instances can be enabled to intercept requests
such as https://example.com/qux-c?arraykey[]=a&arraykey[]=b, etc...

Changes

MockAgents created with the acceptNonStandardSearchParameters "normalize" requests such as https://example.com/qux-c?arraykey[]=a&arraykey[]=b into ones like
https://example.com/qux-c?arraykey=a&arraykey=b so that they can then be handled normally

Features

N/A

Bug Fixes

Fixes #4146

Breaking Changes and Deprecations

None

Status


Note

My implementation supports the case of array values having [] (e.g. a[]=1,a[]=2,a[]=3) and also different array values separated by commas (e.g. a=1,2,3) and that's pretty much it, it could potentially support other syntaxes like the JSON API and Bitbucket API mentioned in https://medium.com/raml-api/arrays-in-query-params-33189628fa68, but that feels to me like quite an overkill right now. I am thinking that probably the cases I am adding support for now should cover most use cases anyways and if the extra ones will be needed in the future (someone opening an issue, etc...) they can always be incrementally added as needed on top of my changes 🤔

@dario-piotrowicz dario-piotrowicz force-pushed the dario/multi-search-params-normalization branch 2 times, most recently from 97cee8d to 6d9cb9d Compare April 4, 2025 19:58
@dario-piotrowicz dario-piotrowicz force-pushed the dario/multi-search-params-normalization branch from cf7daab to 2eb2cb1 Compare April 14, 2025 18:28
@metcoder95 metcoder95 requested a review from mcollina April 20, 2025 09:05
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Member

Actually, can you add docs for this?

@dario-piotrowicz
Copy link
Member Author

thanks @mcollina 🫶 🚀

Of course I'll add the docs right away, I was waiting to hear your thoughts on the API before doing that (as I mentioned above) 👍

@dario-piotrowicz dario-piotrowicz force-pushed the dario/multi-search-params-normalization branch from 2eb2cb1 to c8abf9e Compare April 20, 2025 17:09
@dario-piotrowicz
Copy link
Member Author

ok docs added 🙂 c8abf9e

It was much quicker than I thought 😄, I was initially thinking of adding an example for this but it feels like a bit of an overkill to me right now 🤔, please let me know what you think 🙂

add a new `acceptNonStandardSearchParameters` option to make
instances of `MockAgent` accept search parameters specified
using non-standard syntaxes such as multi-value items specified
with `[]` (e.g. `param[]=1&param[]=2&param[]=3`) and multi-value
items which values are comma separated (e.g. `param=1,2,3`)

Co-authored-by: Carlos Fuentes <me@metcoder.dev>
@dario-piotrowicz dario-piotrowicz force-pushed the dario/multi-search-params-normalization branch from c8abf9e to 36356b1 Compare April 20, 2025 17:18
@dario-piotrowicz dario-piotrowicz changed the title fix: make sure array search params using different syntaxes are supported feat: add new acceptNonStandardSearchParameters MockAgent option Apr 20, 2025
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@metcoder95 metcoder95 merged commit 0daba93 into nodejs:main Apr 21, 2025
28 of 31 checks passed
@dario-piotrowicz dario-piotrowicz deleted the dario/multi-search-params-normalization branch April 21, 2025 10:11
This was referenced May 10, 2025
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.

Bug: MockAgent intercepts don't handle params with square brackets
3 participants