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

feat(interceptor): duplicate query keys throw #1626

Merged
merged 1 commit into from Jul 15, 2019

Conversation

mastermatt
Copy link
Member

Resolves #1623

BREAKING CHANGE: Providing a duplicate search parameter to the query
method throws an error instead of ignoring subsequent values.

Resolves nock#1623

BREAKING CHANGE: Providing a duplicate search parameter to the `query`
method throws an error instead of ignoring subsequent values.
Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

This is great 👏

@gr2m gr2m merged commit a2208d1 into nock:beta Jul 15, 2019
@nockbot
Copy link
Collaborator

nockbot commented Jul 15, 2019

🎉 This PR is included in version 11.0.0-beta.26 🎉

The release is available on:

Your semantic-release bot 📦🚀

@paulmelnikow
Copy link
Member

paulmelnikow commented Jul 15, 2019

Hmm, I was thinking about this a little differently. I was thinking we'd throw if there were multiple attempts to define the query, regardless of whether the keys duplicated each other. Meaning you would get an error if you did .get('/?foo=bar').query({ myQs }) regardless of what's inside myQs. The idea being that is probably a mistake; with one or the other of those going unnoticed.

Or .get('/').query().query(), which probably also is a mistake.

What do you think?

@gr2m
Copy link
Member

gr2m commented Jul 15, 2019

Hmm sounds reasonable. Even if folks might want to merge query options conditionally, they can do that before passing it to .query(). I’d be okay to throw an error if .query() is called more than once

@mastermatt mastermatt deleted the interceptor-query-dup-key branch July 16, 2019 01:14
@mastermatt
Copy link
Member Author

I'm in favor of throwing an error if trying to set query filter data twice, but if we go that route I have two questions:

Should we allow the user to explicitly unset query filtering?
Something like .get(somePathVarThatMightHaveAQuery).query(false) for those cases where users are passing a path var around?

Second: we still need to handle duplicate query keys in some way.
The more I poke around with options, the more I think we have a bug that this PR changed, but didn't fix.
Note that .get('/?foo=one&foo=two') is a valid query and we should probably support it.
I'm thinking that updating the Interceptor.queries attribute from an object to be an array using the "entities" format [[key, value], ...] will be the right approach. That will mean updating the match method too.

@paulmelnikow
Copy link
Member

Something like .get(somePathVarThatMightHaveAQuery).query(false) for those cases where users are passing a path var around?

I think it's not necessary. Nock has so much API surface and if it comes to it they can somePathVarThatMightHaveAQuery.split('?')[0] easily enough.

Note that .get('/?foo=one&foo=two') is a valid query and we should probably support it.

Right! Though since we were silently dropping duplicates before, I figured an explicit error was no worse…

I'm thinking that updating the Interceptor.queries attribute from an object to be an array using the "entities" format [[key, value], ...] will be the right approach. That will mean updating the match method too.

Yes. That makes sense to me. 👍

URLSearchParams and literal query strings would be two ways of specifying queries with duplicated keys.

mastermatt added a commit to mastermatt/nock that referenced this pull request Jul 16, 2019
Continuation of nock#1626

BREAKING CHANGE: Attempting to call `Interceptor.query` twice throws an error.
mastermatt added a commit that referenced this pull request Jul 16, 2019
* feat(interceptor): duplicate query calls throw

Continuation of #1626

BREAKING CHANGE: Attempting to call `Interceptor.query` twice throws an error.
@nockbot
Copy link
Collaborator

nockbot commented Aug 12, 2019

🎉 This PR is included in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this pull request Sep 4, 2019
* feat(interceptor): duplicate query calls throw

Continuation of #1626

BREAKING CHANGE: Attempting to call `Interceptor.query` twice throws an error.
gr2m pushed a commit that referenced this pull request Sep 4, 2019
* feat(interceptor): duplicate query calls throw

Continuation of #1626

BREAKING CHANGE: Attempting to call `Interceptor.query` twice throws an error.
gr2m pushed a commit that referenced this pull request Sep 5, 2019
* feat(interceptor): duplicate query calls throw

Continuation of #1626

BREAKING CHANGE: Attempting to call `Interceptor.query` twice throws an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants