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: Don't add null values to query string. #5108

Merged

Conversation

ChronosMasterOfAllTime
Copy link
Contributor

@ChronosMasterOfAllTime ChronosMasterOfAllTime commented Oct 12, 2022

This aims to resolve Feature Request #5107 and #5094

We added a "backwards compatibility" to allow serializing params with our own custom function instead of the current iterative toString approach.

@ghost
Copy link

ghost commented Oct 12, 2022

Yes please!

@ChronosMasterOfAllTime
Copy link
Contributor Author

@jasonsaayman were there merge conflicts? Seems like some odd things from the merge. (Like the readme for example)

@ChronosMasterOfAllTime ChronosMasterOfAllTime changed the title feat: add boolean flag to mimic pre 1.x behavior for paramsSerializer custom function Fix: Don't add null values to query string. Oct 14, 2022
Copy link
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

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

Looks good 🚀

@jasonsaayman jasonsaayman merged commit b0ebf9f into axios:v1.x Oct 15, 2022
@ChronosMasterOfAllTime ChronosMasterOfAllTime deleted the feat/params_serializer_compat branch October 15, 2022 15:24
@ChronosMasterOfAllTime
Copy link
Contributor Author

Thank you!

Tbhesswebber pushed a commit to Tbhesswebber/axios that referenced this pull request Oct 15, 2022
* feat: add  boolean flag to mimic pre 1.x behavior for paramsSerializer custom function

* chore: update ParamsSerializer Readme

* fix: dont slice hash off URL if not appending params

* Omit nulls from formData serialization

* fix: dont add nulls or undefined values to arrays either

* readme update

* fix test

* chore: documentation

* chore: do TS properly

Co-authored-by: Jay <jasonsaayman@gmail.com>
@ghost ghost mentioned this pull request Nov 3, 2022
@havardthom
Copy link

This PR contradicts the discusssion here #1139 and solution here #1987

I have a use case for null query param, as many people in #1139 . Will this be added to Axios in the future?

@ChronosMasterOfAllTime
Copy link
Contributor Author

This PR contradicts the discusssion here #1139 and solution here #1987

I have a use case for null query param, as many people in #1139 . Will this be added to Axios in the future?

Nulls were being included as empty string some_param=, not some_param=null. I would think you would want the latter. Also if your API is set to deserialze the QS it should automatically handle missing fields as null/nil/None/undefined.

@OzQu
Copy link

OzQu commented Nov 14, 2022

As far as I understood, there is multiple use cases to have query string with keys without values

  it('should support params', function () {
    expect(buildURL('/foo', {
      foo: 'bar',
      isUndefined: undefined,
      isNull: null
    })).toEqual('/foo?foo=bar&isNull');
  });

Could that be considered?

@ghost
Copy link

ghost commented Nov 16, 2022

@OzQu I get the ask, however if you look at the behavior, an unset query Param returns an empty string when parsed via URLSearchParams

image

If you want null as a value for test, it would have to be handled by your API. I would think omitting the value is the equivalent of ?someVal when deserializing the request.

We can add it back in, but know it's up to the API to correctly handle this behavior when deserializing into your request object.

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

4 participants