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

Allow the query option to be a URLSearchParams instance #565

Merged
merged 8 commits into from Aug 23, 2018
Merged

Allow the query option to be a URLSearchParams instance #565

merged 8 commits into from Aug 23, 2018

Conversation

lorenzofox3
Copy link
Contributor

@lorenzofox3 lorenzofox3 commented Aug 15, 2018

Fixes #554

@sindresorhus
Copy link
Owner

@lorenzofox3 This causes a test failure.

@lorenzofox3
Copy link
Contributor Author

@sindresorhus
I think the test is failing is because the URLSearchParams implements properly the standard url encoder parser and serializer which means ?foo is correctly parsed and serialized to ?foo= (which dose not match the redirect url ?foo of the test server). I see then different solutions.

  1. Modify the test and consider ?foo is equivalent ?foo= on the test server side (which is the case according to the spec aforementioned if I understand correctly)
  2. Change the implementation to have our own toString so that empty values are ignored and the = sign is not appended. However this could lead to inconsistent behavior.
    query parameters with following parameters may not output the same queryString:
    ?foo
    ?foo=''
    ?foo=''
    {query:undefined}
    {query:''}

On a side note: I am not sure whether it is a problem with the test framework or the reporter but when running the tests I man not able to say it is actually failing: when I run the tests the final output is
screen shot 2018-08-15 at 11 25 49 pm

@szmarczak
Copy link
Collaborator

szmarczak commented Aug 22, 2018

@lorenzofox3 is right.

This:

http.on('/relativeQuery?bang', (request, response) => {

should be

 http.on('/relativeQuery?bang=', (request, response) => { 

and the tests would pass. I think we should use lukeed/polka because it's very lightweight and blazing fast. I highly recommend it :)

@szmarczak szmarczak changed the title Fix #554 allows query option parameters to be a URLSearchParams instance Allow the query option to be a URLSearchParams instance Aug 23, 2018
@szmarczak szmarczak merged commit b8a086f into sindresorhus:master Aug 23, 2018
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

3 participants