Skip to content

paramsSerializer is not working in v0.28.0 #6262

@briwa

Description

@briwa

Describe the bug

Although there's a backport in #6227, in v0.28.0, the serializer isn't working as expected. This is because the v0.28.0 version of buildUrl (code) is simply only taking options.encode, not taking options.serializer into account:

var _encode = options && options.encode || encode;
var serializerParams = utils.isURLSearchParams(params) ?
params.toString() :
new AxiosURLSearchParams(params, options).toString(_encode);
if (serializerParams) {
url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams;
}

This seems to be a refactor to match the v1.x version, because in v0.27.2 at least (code), it takes the paramSerializer function into account:

var serializedParams;
if (paramsSerializer) {
serializedParams = paramsSerializer(params);

In order for #6227 to actually work, there needs to be a backport similar to #5113 towards v0.x

To Reproduce

  • Set the version to v0.28.0
  • Set the paramsSerializer function
  • It won't work

Code snippet

// Simply following https://axios-http.com/docs/req_config

axios.create({
  paramsSerializer: function (params) {
    return Qs.stringify(params, {arrayFormat: 'brackets'})
  },
})

Expected behavior

The parameters should be serialized, but it didn't

Axios Version

v0.28.0

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions