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

[0.28.1] options.paramsSerializer as function don't work #6341

Open
vernou opened this issue Apr 3, 2024 · 2 comments
Open

[0.28.1] options.paramsSerializer as function don't work #6341

vernou opened this issue Apr 3, 2024 · 2 comments

Comments

@vernou
Copy link

vernou commented Apr 3, 2024

Describe the bug

We have a custom serialize method that is passed to axios by options.paramsSerializer.
It's work fine with axios@0.28.0, but from axios@0.28.1, it throw the error :

options must be an object

To Reproduce

No response

Code snippet

const conf = {
  paramsSerializer: function (params: any) {
    return qs.stringify(params, { arrayFormat: 'repeat' })
  }
}

const instance = axios.create(conf)
instance.request()

Expected behavior

The HTTP request is executed (like in 0.28.0).

Axios Version

0.28.1

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

The problem come from the commit 111811eadc849c08a3a2074930c50f68afa6eba5.

In axios.js, this check was added :

if (paramsSerializer !== undefined) {
  validator.assertOptions(paramsSerializer, {
    encode: validators.function,
    serialize: validators.function
  }, true);
}

And validator.assertOptions throw the error when the first parameter isn't a object.

Moreover, the next line manage the case where paramsSerializer is a function :

utils.isFunction(paramsSerializer) && (config.paramsSerializer = {serialize: paramsSerializer});

A solution will be to down the check after the below line transform paramsSerializer from function to object, so the check will be ok.

@vernou
Copy link
Author

vernou commented Apr 4, 2024

If you want, I can do the PR?

@solonzhu
Copy link

Just wanted to note this is also affecting me -- this issue combined with issue #6262 means that if for whatever reason I need to pass the paramsSerializer as a function, then I cannot upgrade to any 0.28.x version, which is a problem because I'm trying to fix GHSA-wf5p-g6vw-rhxx.

I've opened a PR to fix this (linked above) and would greatly appreciate if I could get a maintainer to take a look!

(Sorry Benjamin if this is stepping on your toes, the tests you copied over didn't run and I don't know what the etiquette is for this sort of change).

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

No branches or pull requests

2 participants